結果

問題 No.277 根掘り葉掘り
ユーザー TawaraTawara
提出日時 2015-09-04 23:38:51
言語 Python2
(2.7.18)
結果
WA  
実行時間 -
コード長 335 bytes
コンパイル時間 453 ms
コンパイル使用メモリ 6,644 KB
実行使用メモリ 30,208 KB
最終ジャッジ日時 2023-09-26 07:10:04
合計ジャッジ時間 6,832 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
5,996 KB
testcase_01 AC 11 ms
5,972 KB
testcase_02 WA -
testcase_03 AC 12 ms
6,120 KB
testcase_04 AC 12 ms
5,948 KB
testcase_05 AC 12 ms
6,068 KB
testcase_06 AC 11 ms
6,084 KB
testcase_07 AC 11 ms
5,964 KB
testcase_08 AC 11 ms
6,012 KB
testcase_09 RE -
testcase_10 AC 498 ms
28,104 KB
testcase_11 AC 563 ms
29,684 KB
testcase_12 RE -
testcase_13 WA -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

def dfs(b,h,d):
	R[h] = d
	L[h] = 0 if len(e[h])==1 and h!=0 else min(dfs(h,nxt,d+1) for nxt in e[h] if nxt!=b)
	return L[h]+1
N = input()
e = [[] for i in range(N)]
R = [0]*N; L = [0]*N
for i in range(N-1):
	x,y = map(int,raw_input().split())
	e[x-1].append(y-1)
	e[y-1].append(x-1)
dfs(0,0,0)
for i in range(N):
	print min(R[i],L[i])
0