結果
問題 |
No.277 根掘り葉掘り
|
ユーザー |
![]() |
提出日時 | 2015-10-04 17:22:06 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 510 bytes |
コンパイル時間 | 106 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 31,232 KB |
最終ジャッジ日時 | 2024-07-19 19:32:19 |
合計ジャッジ時間 | 7,742 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 WA * 1 |
other | AC * 12 WA * 6 |
ソースコード
import collections N = int(input()) tree = [[] for i in range(N)] for i in range(N - 1): x, y = map(int, input().split()) tree[x - 1].append(y - 1) tree[y - 1].append(x - 1) L=[N*2]*N dq = collections.deque() dq.append(0) for i in range(N): if len(tree[i]) == 1: L[i] = 0 dq.append(i) while dq: cur = dq.popleft() for t in tree[cur]: if L[t] <= L[cur] + 1: continue L[t] = L[cur] + 1 dq.append(t) for i in range(N): print(L[i])