結果

問題 No.277 根掘り葉掘り
ユーザー TawaraTawara
提出日時 2015-09-05 00:18:44
言語 Python2
(2.7.18)
結果
WA  
実行時間 -
コード長 510 bytes
コンパイル時間 672 ms
コンパイル使用メモリ 6,636 KB
実行使用メモリ 259,236 KB
最終ジャッジ日時 2023-09-26 07:33:29
合計ジャッジ時間 10,940 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
5,940 KB
testcase_01 AC 12 ms
6,160 KB
testcase_02 WA -
testcase_03 AC 13 ms
6,144 KB
testcase_04 AC 12 ms
5,972 KB
testcase_05 AC 11 ms
6,172 KB
testcase_06 AC 12 ms
6,108 KB
testcase_07 AC 12 ms
6,044 KB
testcase_08 AC 12 ms
6,148 KB
testcase_09 AC 1,660 ms
259,236 KB
testcase_10 AC 583 ms
33,584 KB
testcase_11 AC 623 ms
30,880 KB
testcase_12 AC 1,094 ms
143,604 KB
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(r,b,h,d):
	if RL[h] > d:
		RL[h] = d
		if len(e[h]) == 1 and h != r:
			leaf.add(h)
			RL[h] = 0
		else:
			tmp = min(dfs(r,h,nxt,d+1) for nxt in e[h] if nxt != b)
			if tmp < RL[h]:
				RL[h] = tmp
	return RL[h] + 1
N = input()
e = [[] for i in range(N)]
leaf = set([0])
RL = [N]*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)
for i in range(N):
	if i in leaf:
		dfs(i,i,i,0)
for i in range(N):
	print RL[i]
0