結果
問題 | No.277 根掘り葉掘り |
ユーザー | matsu7874 |
提出日時 | 2015-10-04 17:18:02 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 804 bytes |
コンパイル時間 | 103 ms |
コンパイル使用メモリ | 10,752 KB |
実行使用メモリ | 40,820 KB |
最終ジャッジ日時 | 2023-09-27 01:57:48 |
合計ジャッジ時間 | 7,860 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 19 ms
8,528 KB |
testcase_01 | AC | 19 ms
8,412 KB |
testcase_02 | AC | 19 ms
8,624 KB |
testcase_03 | AC | 20 ms
8,540 KB |
testcase_04 | AC | 19 ms
8,660 KB |
testcase_05 | AC | 20 ms
8,536 KB |
testcase_06 | AC | 20 ms
8,508 KB |
testcase_07 | AC | 20 ms
8,564 KB |
testcase_08 | AC | 19 ms
8,488 KB |
testcase_09 | AC | 791 ms
32,872 KB |
testcase_10 | AC | 672 ms
35,416 KB |
testcase_11 | AC | 1,151 ms
31,944 KB |
testcase_12 | TLE | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
ソースコード
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) R = [N * 2] * N L = [N * 2] * N dq = collections.deque() R[0] = 0 dq.append(0) while dq: cur = dq.popleft() for t in tree[cur]: if R[t] < R[cur] + 1: continue R[t] = R[cur] + 1 dq.append(t) leaf = [] for i in range(N): if len(tree[i]) == 1: L[i] = 0 leaf.append((R[i], i)) leaf.sort() for r, l in leaf: dq.append(l) 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(min(R[i], L[i]))