結果
問題 | No.277 根掘り葉掘り |
ユーザー | matsu7874 |
提出日時 | 2015-10-04 17:22:06 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 510 bytes |
コンパイル時間 | 135 ms |
コンパイル使用メモリ | 10,832 KB |
実行使用メモリ | 29,056 KB |
最終ジャッジ日時 | 2023-09-27 01:58:15 |
合計ジャッジ時間 | 8,018 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | AC | 20 ms
8,492 KB |
testcase_02 | AC | 18 ms
8,584 KB |
testcase_03 | AC | 19 ms
8,408 KB |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | AC | 19 ms
8,592 KB |
testcase_08 | AC | 19 ms
8,608 KB |
testcase_09 | AC | 580 ms
29,056 KB |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | AC | 621 ms
27,852 KB |
testcase_14 | AC | 600 ms
28,292 KB |
testcase_15 | AC | 603 ms
28,076 KB |
testcase_16 | AC | 597 ms
27,620 KB |
testcase_17 | AC | 594 ms
27,928 KB |
testcase_18 | AC | 594 ms
27,588 KB |
testcase_19 | AC | 577 ms
27,816 KB |
ソースコード
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])