作者:Ms.lin 链接:https://www.nowcoder.com/discuss/177870 来源:牛客网 逃生问题: 思路:根结点左右子树的最大结点数。本地测试通过,提交不通过,不知道哪错了,大佬们帮忙看看 import collections import sys n = int(input()) edges = [] while True:     a = []     s = input()     if s != "":         for x in s.split():             a.append(int(x))         edges.append(a)     else:         break graph = collections.defaultdict(set) for u, v in edges:     graph[u].add(v)     graph[v].add(u) def dfs(graph, node, visited):     count = 1     visited[node] = True     for child in graph[node]:         if not visited[child]:             count += dfs(graph, child, visited)     return count res = 0 visited = [False] * (n + 1) visited[1] = True for child in graph[1]:     nodeNums = dfs(graph, child, visited)     if res < nodeNums:         res = nodeNums sys.stdout.write(str(res)+"\n")
点赞 4

相关推荐

程序员牛肉:你这简历有啥值得拷打的?在牛客你这种简历一抓一大把,也就是个人信息不一样而已。 关键要去找亮点,亮点啊,整个简历都跟流水线生产出来的一样。
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务