結果

問題 No.806 木を道に
ユーザー ronpooronpoo
提出日時 2023-09-19 13:42:40
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 558 bytes
コンパイル時間 912 ms
コンパイル使用メモリ 10,972 KB
実行使用メモリ 54,764 KB
最終ジャッジ日時 2023-09-19 13:42:53
合計ジャッジ時間 12,125 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,912 KB
testcase_01 AC 16 ms
7,848 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 17 ms
7,800 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 16 ms
7,876 KB
testcase_08 AC 17 ms
7,784 KB
testcase_09 AC 17 ms
7,852 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 303 ms
38,808 KB
testcase_25 AC 469 ms
54,764 KB
testcase_26 AC 142 ms
19,648 KB
testcase_27 AC 489 ms
45,848 KB
testcase_28 AC 28 ms
8,988 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**6)

N = int(input())
ab = [list(map(int, input().split())) for _ in range(N-1)]

G = [[] for _ in range(N)]
for i in range(N-1):
    a, b = ab[i]
    a -= 1
    b -= 1
    G[a].append(b)
    G[b].append(a)

def dfs(now, prev):
    for nxt in G[now]:
        if nxt == prev:
            continue
        dist[nxt] = dist[now] + 1
        dfs(nxt, now)
        
dist = [float('inf')] * N
dist[0] = 0
dfs(0, -1)
idx = dist.index(max(dist))
dist = [float('inf')] * N
dist[idx] = 0
dfs(idx, -1)
ans = N-1-max(dist)
print(ans)
0