首页 > 编程语言 > 详细

python(not pypy), dfs, thread?

时间:2020-04-26 23:44:11      阅读:74      评论:0      收藏:0      [点我收藏+]

https://codeforces.com/contest/1336/problem/A

import sys
import threading
from collections import defaultdict
sys.setrecursionlimit(10**6)
threading.stack_size(10**8)
input = sys.stdin.readline

B = []
A = defaultdict(list)


def dfs(now, fa, depth):
    son = 1
    for to in A[now]:
        if to != fa:
            son += dfs(to, now, depth + 1)
    B.append(depth - son)
    return son


def main():
    n, m = map(int, input().split())
    for i in range(n - 1):
        x, y = map(int, input().split())
        x -= 1
        y -= 1
        A[x].append(y)
        A[y].append(x)
    dfs(0, -1, 1)
    print(sum(sorted(B, reverse=True)[:m]))


t = threading.Thread(target=main)
t.start()
t.join()

python(not pypy), dfs, thread?

原文:https://www.cnblogs.com/reshuffle/p/12783497.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!