結果

問題 No.277 根掘り葉掘り
ユーザー convexineqconvexineq
提出日時 2020-12-26 17:39:27
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 547 bytes
コンパイル時間 182 ms
コンパイル使用メモリ 81,568 KB
実行使用メモリ 116,344 KB
最終ジャッジ日時 2023-10-25 01:11:14
合計ジャッジ時間 5,887 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,292 KB
testcase_01 AC 37 ms
53,292 KB
testcase_02 WA -
testcase_03 AC 43 ms
53,292 KB
testcase_04 AC 39 ms
53,292 KB
testcase_05 AC 39 ms
53,292 KB
testcase_06 AC 39 ms
53,292 KB
testcase_07 AC 39 ms
53,292 KB
testcase_08 AC 37 ms
53,292 KB
testcase_09 AC 247 ms
106,388 KB
testcase_10 AC 244 ms
116,344 KB
testcase_11 AC 284 ms
106,392 KB
testcase_12 AC 268 ms
106,396 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
g = [[] for _ in range(n)]
for i in range(n-1):
    a,b = [int(i) for i in input().split()]
    g[a-1].append(b-1)
    g[b-1].append(a-1)
 
order = []
st = [0]
parent = [-1]*n
L = [0]*n
while st:
    v = st.pop()
    order.append(v)
    for c in g[v]:
        if c != parent[v]:
            st.append(c)
            parent[c] = v
            L[c] = L[v]+1

INF = 1<<30
R = [INF]*n
for i in order[::-1]:
    if R[i] == INF: R[i] = 0
    p = parent[i]
    R[p] = min(R[p],R[i]+1)
print(*(min(li,ri) for li,ri in zip(L,R)), sep="\n")
0