結果
問題 |
No.806 木を道に
|
ユーザー |
![]() |
提出日時 | 2023-12-31 21:09:49 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 607 bytes |
コンパイル時間 | 436 ms |
コンパイル使用メモリ | 82,296 KB |
実行使用メモリ | 120,228 KB |
最終ジャッジ日時 | 2024-09-27 17:11:54 |
合計ジャッジ時間 | 6,639 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 9 WA * 18 |
ソースコード
N = int(input()) UV = [list(map(int, input().split())) for _ in range(N - 1)] D = [0] * N E = [[] for _ in range(N)] for u, v in UV: u -= 1 v -= 1 E[u].append(v) E[v].append(u) def bfs(a): q = [a] cnt = 0 nv = [True] * N nv[a] = False while q: q2 = [] lastq = q[:] while q: x = q.pop(-1) for y in E[x]: if nv[y]: nv[y] = False q2.append(y) q, q2 = q2, q cnt += 1 return (cnt, lastq) cnt, lastq = bfs(0) cnt, lastq = bfs(lastq[0]) print(N - cnt)