結果
問題 | No.277 根掘り葉掘り |
ユーザー | tktk_snsn |
提出日時 | 2020-12-31 01:43:57 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 692 bytes |
コンパイル時間 | 267 ms |
コンパイル使用メモリ | 82,400 KB |
実行使用メモリ | 108,044 KB |
最終ジャッジ日時 | 2024-04-17 03:25:08 |
合計ジャッジ時間 | 3,802 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 33 ms
51,840 KB |
testcase_01 | AC | 33 ms
52,224 KB |
testcase_02 | WA | - |
testcase_03 | AC | 33 ms
52,352 KB |
testcase_04 | AC | 33 ms
52,480 KB |
testcase_05 | AC | 31 ms
52,736 KB |
testcase_06 | AC | 33 ms
52,480 KB |
testcase_07 | AC | 31 ms
52,224 KB |
testcase_08 | AC | 31 ms
52,352 KB |
testcase_09 | AC | 134 ms
96,924 KB |
testcase_10 | AC | 136 ms
108,044 KB |
testcase_11 | AC | 158 ms
96,896 KB |
testcase_12 | AC | 157 ms
96,896 KB |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
ソースコード
import sys input = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 7) n = int(input()) G = [[] for _ in range(n)] for _ in range(n - 1): a, b = map(int, input().split()) a -= 1 b -= 1 G[a].append(b) G[b].append(a) d = [-1] * n d[0] = 0 topo = [] que = [0] par = [-1] * n while que: s = que.pop() topo.append(s) for t in G[s]: if t == par[s]: continue par[t] = s G[t].remove(s) d[t] = d[s] + 1 que.append(t) dd = [10**9] * n for s in topo[::-1]: if not G[s]: dd[s] = 0 continue for t in G[s]: dd[s] = min(dd[s], dd[t] + 1) for a, b in zip(d, dd): print(min(a, b))