結果
| 問題 | No.806 木を道に |
| コンテスト | |
| ユーザー |
👑 Kazun
|
| 提出日時 | 2020-10-27 16:12:48 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 461 bytes |
| 記録 | |
| コンパイル時間 | 279 ms |
| コンパイル使用メモリ | 82,304 KB |
| 実行使用メモリ | 113,296 KB |
| 最終ジャッジ日時 | 2024-07-21 21:56:58 |
| 合計ジャッジ時間 | 6,667 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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