結果

問題 No.277 根掘り葉掘り
ユーザー TawaraTawara
提出日時 2015-09-05 00:38:11
言語 Python2
(2.7.18)
結果
AC  
実行時間 1,362 ms / 3,000 ms
コード長 377 bytes
コンパイル時間 182 ms
コンパイル使用メモリ 6,508 KB
実行使用メモリ 158,656 KB
最終ジャッジ日時 2023-09-26 07:41:12
合計ジャッジ時間 9,337 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
6,060 KB
testcase_01 AC 12 ms
6,056 KB
testcase_02 AC 11 ms
6,200 KB
testcase_03 AC 12 ms
6,292 KB
testcase_04 AC 12 ms
6,216 KB
testcase_05 AC 12 ms
6,076 KB
testcase_06 AC 12 ms
6,116 KB
testcase_07 AC 12 ms
6,240 KB
testcase_08 AC 11 ms
6,188 KB
testcase_09 AC 1,008 ms
158,656 KB
testcase_10 AC 510 ms
27,256 KB
testcase_11 AC 571 ms
28,752 KB
testcase_12 AC 1,362 ms
115,100 KB
testcase_13 AC 582 ms
29,316 KB
testcase_14 AC 573 ms
37,300 KB
testcase_15 AC 662 ms
48,300 KB
testcase_16 AC 661 ms
37,524 KB
testcase_17 AC 601 ms
38,480 KB
testcase_18 AC 596 ms
33,332 KB
testcase_19 AC 581 ms
31,640 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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