結果

問題 No.806 木を道に
ユーザー flippergoflippergo
提出日時 2020-12-30 18:46:28
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 672 bytes
コンパイル時間 263 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 94,888 KB
最終ジャッジ日時 2024-04-16 19:37:52
合計ジャッジ時間 5,247 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
53,504 KB
testcase_01 AC 40 ms
53,632 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 43 ms
53,632 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 40 ms
53,632 KB
testcase_08 AC 39 ms
53,888 KB
testcase_09 AC 40 ms
53,632 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 130 ms
86,272 KB
testcase_25 AC 153 ms
90,792 KB
testcase_26 AC 111 ms
82,920 KB
testcase_27 AC 176 ms
94,336 KB
testcase_28 AC 86 ms
77,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
N = int(input())
G = {i:[] for i in range(1,N+1)}
for _ in range(N-1):
    a,b = map(int,input().split())
    G[a].append(b)
    G[b].append(a)
d1 = [-1 for _ in range(N+1)]
d1[1] = 0
que = deque([(1,0)])
while que:
    x,d = que.popleft()
    for y in G[x]:
        if d1[y]<0:
            d1[y]=d+1
            que.append((y,d+1))
dmax = 0
for i in range(1,N+1):
    if dmax<d1[i]:
        dmax = d1[i]
        ind = i
d2 = [-1 for _ in range(N+1)]
d2[ind]=0
que = deque([(ind,0)])
while que:
    x,d = que.popleft()
    for y in G[x]:
        if d2[y]<0:
            d2[y]=d+1
            que.append((y,d+1))
dmax = max(d2)
print(N-1-dmax)
0