cpp 版显示 wrong answer,没有输出, python 版显示 runtime error,没有提示,但是本地测试过测试用例都没有问题,算法应该是正确的。
Last active
October 20, 2015 03:30
-
-
Save jo32/3f67245defcec6f62ae5 to your computer and use it in GitHub Desktop.
CODEFORCE 120F
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cases = int(raw_input()) | |
sumLength = 0 | |
def maxHeight(edgeDict, root, visited=set([])): | |
visited.add(root); | |
return max([maxHeight(edgeDict, child, visited) if child not in visited else -1 for child in edgeDict[root]]) + 1 | |
for case in range(cases): | |
edgeDict = {} | |
line = [int(i) for i in raw_input().split(' ')] | |
ni = line[0]; | |
for i in range(ni - 1): | |
u = line[i * 2 + 1] | |
v = line[i * 2 + 2] | |
if u in edgeDict: | |
edgeDict[u].append(v) | |
else: | |
edgeDict[u] = [v] | |
if v in edgeDict: | |
edgeDict[v].append(u) | |
else: | |
edgeDict[v] = [u] | |
sumLength += max([maxHeight(edgeDict, i, set([])) for i in range(1, ni + 1)]) | |
print sumLength |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment