結果

問題 No.806 木を道に
ユーザー hedwig100hedwig100
提出日時 2020-04-22 21:52:47
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 620 bytes
コンパイル時間 99 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 31,108 KB
最終ジャッジ日時 2024-04-20 09:58:12
合計ジャッジ時間 8,598 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,752 KB
testcase_01 AC 31 ms
10,752 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 31 ms
10,752 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 31 ms
10,752 KB
testcase_08 AC 30 ms
10,880 KB
testcase_09 AC 31 ms
10,880 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 268 ms
21,760 KB
testcase_25 AC 386 ms
27,136 KB
testcase_26 AC 155 ms
16,512 KB
testcase_27 AC 456 ms
29,184 KB
testcase_28 AC 42 ms
11,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
G = [[] for _ in range(n)]
for _ in range(n - 1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    G[a].append(b)
    G[b].append(a)

def max_depth(s):
    ans = 0
    idx = 0
    depth = [-1] * n
    depth[s] = 0
    stack = [s]
    while stack:
        p = stack.pop()
        for v in G[p]:
            if  depth[v] >= 0:
                continue
            depth[v] = depth[p] + 1
            if ans < depth[v]:
                ans = depth[v]
                idx = v
            stack.append(v)

    return ans,idx

depth,s = max_depth(0)
max_dep,i = max_depth(s)
print(n - max_dep - 1)
0