結果

問題 No.277 根掘り葉掘り
コンテスト
ユーザー norioc
提出日時 2026-05-25 03:07:10
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
WA  
実行時間 -
コード長 478 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 154 ms
コンパイル使用メモリ 85,248 KB
実行使用メモリ 104,924 KB
最終ジャッジ日時 2026-05-25 03:07:16
合計ジャッジ時間 5,670 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 8 WA * 7 RE * 3
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from collections import defaultdict

INF = 1 << 62
N = int(input())

adj = defaultdict(list)
for _ in range(N-1):
    U, V = map(lambda x: int(x)-1, input().split())
    adj[U].append(V)
    adj[V].append(U)


def dfs(v, par, dep):
    res = INF
    for to in adj[v]:
        if to == par: continue
        res = min(res, dfs(to, v, dep+1))

    if res == INF:
        res = 0

    ans[v] = min(dep, res)
    return res + 1


ans = [INF] * N
dfs(0, -1, 0)
print(*ans, sep='\n')
0