結果

問題 No.277 根掘り葉掘り
ユーザー yaoshimaxyaoshimax
提出日時 2016-05-13 11:11:47
言語 Python2
(2.7.18)
結果
TLE  
実行時間 -
コード長 470 bytes
コンパイル時間 64 ms
コンパイル使用メモリ 6,912 KB
実行使用メモリ 13,888 KB
最終ジャッジ日時 2024-04-15 15:28:10
合計ジャッジ時間 4,643 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

import sys
sys.setrecursionlimit(100000)

N=int(raw_input())
E=[[] for i in range(N)]
for i in range(N-1):
    x,y = map(int,raw_input().split())
    E[x-1].append(y-1)
dist=[-1 for i in range(N)]
def rec(n,cur):
    dist[n]=cur
    d=100000
    for m in E[n]:
        d=min(d,rec(m,cur+1))
    if d==100000:
        d=0
    if d<cur:
        for m in E[n]:
            rec(m,d+1)
    dist[n]=min(dist[n],d)
    return d+1

rec(0,0)
for i in range(N):
    print dist[i]
0