結果

問題 No.277 根掘り葉掘り
ユーザー TawaraTawara
提出日時 2015-09-05 00:33:42
言語 Python2
(2.7.18)
結果
AC  
実行時間 1,360 ms / 3,000 ms
コード長 405 bytes
コンパイル時間 619 ms
コンパイル使用メモリ 6,604 KB
実行使用メモリ 158,712 KB
最終ジャッジ日時 2023-09-26 07:35:02
合計ジャッジ時間 9,628 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
5,920 KB
testcase_01 AC 11 ms
6,132 KB
testcase_02 AC 11 ms
6,004 KB
testcase_03 AC 12 ms
6,092 KB
testcase_04 AC 12 ms
6,188 KB
testcase_05 AC 11 ms
6,016 KB
testcase_06 AC 12 ms
6,048 KB
testcase_07 AC 12 ms
5,948 KB
testcase_08 AC 11 ms
5,920 KB
testcase_09 AC 985 ms
158,712 KB
testcase_10 AC 500 ms
27,340 KB
testcase_11 AC 543 ms
28,920 KB
testcase_12 AC 1,360 ms
115,036 KB
testcase_13 AC 600 ms
29,276 KB
testcase_14 AC 597 ms
37,312 KB
testcase_15 AC 678 ms
48,408 KB
testcase_16 AC 669 ms
37,636 KB
testcase_17 AC 579 ms
38,400 KB
testcase_18 AC 590 ms
33,192 KB
testcase_19 AC 565 ms
31,636 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(1000000)
def dfs(r,b,h,d):
	RL[h] = d
	if len(e[h]) == 1 and h != r:
		dfs(h,h,h,0)
	else:
		for nxt in e[h]:
			if nxt != b and d+1 < RL[nxt]:
				dfs(r,h,nxt,d+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)
dfs(0,0,0,0)
for i in range(N):
	print RL[i]
0