結果

問題 No.277 根掘り葉掘り
ユーザー yaoshimaxyaoshimax
提出日時 2016-05-13 11:49:09
言語 Python2
(2.7.18)
結果
WA  
実行時間 -
コード長 589 bytes
コンパイル時間 84 ms
コンパイル使用メモリ 7,040 KB
実行使用メモリ 25,300 KB
最終ジャッジ日時 2024-04-15 15:28:22
合計ジャッジ時間 5,806 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
6,400 KB
testcase_01 AC 12 ms
6,272 KB
testcase_02 AC 12 ms
6,272 KB
testcase_03 AC 12 ms
6,400 KB
testcase_04 AC 12 ms
6,144 KB
testcase_05 AC 12 ms
6,400 KB
testcase_06 AC 12 ms
6,528 KB
testcase_07 WA -
testcase_08 AC 12 ms
6,400 KB
testcase_09 WA -
testcase_10 AC 455 ms
23,508 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(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 update(n,cur):
    if dist[n] < cur:
        return
    dist[n]=cur
    for m in E[n]:
        update(m,cur+1)

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]:
            update(m,d+1)
    dist[n]=min(dist[n],d)
    return d+1

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