結果
問題 | No.277 根掘り葉掘り |
ユーザー |
![]() |
提出日時 | 2015-10-04 17:23:18 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 725 ms / 3,000 ms |
コード長 | 529 bytes |
コンパイル時間 | 143 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 31,104 KB |
最終ジャッジ日時 | 2024-07-19 19:32:29 |
合計ジャッジ時間 | 9,364 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 18 |
ソースコード
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() L[0] = 0 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])