結果

問題 No.806 木を道に
ユーザー 👑 KazunKazun
提出日時 2020-10-27 16:12:48
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 461 bytes
コンパイル時間 1,104 ms
コンパイル使用メモリ 87,156 KB
実行使用メモリ 113,812 KB
最終ジャッジ日時 2023-09-29 03:18:24
合計ジャッジ時間 9,901 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
71,556 KB
testcase_01 AC 96 ms
71,468 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 93 ms
71,644 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 96 ms
71,588 KB
testcase_08 AC 95 ms
71,836 KB
testcase_09 AC 95 ms
71,856 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 191 ms
93,572 KB
testcase_25 AC 219 ms
101,776 KB
testcase_26 AC 177 ms
90,064 KB
testcase_27 AC 259 ms
113,812 KB
testcase_28 AC 138 ms
79,004 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

def bfs(v):
    T=[-1]*(N+1)
    T[v]=0
    Q=deque([v])

    while Q:
        w=Q.popleft()
        for u in E[w]:
            if T[u]==-1:
                T[u]=T[w]+1
                Q.append(u)

    x=max(range(1,N+1),key=lambda x:T[x])
    return x,T[x]

N=int(input())
E=[set() for _ in range(N+1)]

for _ in range(N-1):
    a,b=map(int,input().split())
    E[a].add(b)
    E[b].add(a)

u,_=bfs(1)
_,d=bfs(u)

print((N-1)-d)
0