結果
| 問題 | No.806 木を道に |
| コンテスト | |
| ユーザー |
👑 Kazun
|
| 提出日時 | 2020-10-27 16:12:48 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 461 bytes |
| 記録 | |
| コンパイル時間 | 186 ms |
| コンパイル使用メモリ | 85,496 KB |
| 実行使用メモリ | 117,112 KB |
| 最終ジャッジ日時 | 2026-04-03 06:10:39 |
| 合計ジャッジ時間 | 5,072 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 9 WA * 18 |
ソースコード
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)
Kazun