結果

問題 No.277 根掘り葉掘り
ユーザー roiti46roiti46
提出日時 2015-09-04 23:34:11
言語 Python2
(2.7.18)
結果
WA  
実行時間 -
コード長 710 bytes
コンパイル時間 612 ms
コンパイル使用メモリ 6,476 KB
実行使用メモリ 36,004 KB
最終ジャッジ日時 2023-09-26 07:00:17
合計ジャッジ時間 8,441 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
5,920 KB
testcase_01 AC 10 ms
5,956 KB
testcase_02 AC 11 ms
5,936 KB
testcase_03 AC 12 ms
6,116 KB
testcase_04 AC 12 ms
5,944 KB
testcase_05 AC 11 ms
5,912 KB
testcase_06 AC 11 ms
6,084 KB
testcase_07 WA -
testcase_08 AC 11 ms
5,984 KB
testcase_09 WA -
testcase_10 AC 622 ms
32,856 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(1000000)

def dfs(i, dr, dl):
    R[i] = dr
    if dl < L[i]:
        L[i] = dl
    else:
        dl = L[i]
        for j in par[i]:
            up(j, dl + 1)
    for j in chil[i]:
        dfs(j, dr + 1, dl + 1)

def up(i, d):
    if d >= L[i]: return
    L[i] = d
    for j in par[i]:
        up(j, d + 1)

N = int(raw_input())
par, chil = [[] for i in xrange(N)], [[] for i in xrange(N)]

for loop in xrange(N - 1):
    x, y = map(int, raw_input().split())
    x -= 1
    y -= 1
    chil[x].append(y)
    par[y].append(x)

R, L = [0] * N, [1e9] * N
for i in xrange(N):
    if len(chil[i]) == 0:
        up(i, 0)
dfs(0, 0, L[0])

for i in xrange(N):
    print min(R[i], L[i])
0