結果

問題 No.277 根掘り葉掘り
ユーザー TawaraTawara
提出日時 2015-09-05 01:25:55
言語 Python2
(2.7.18)
結果
AC  
実行時間 698 ms / 3,000 ms
コード長 355 bytes
コンパイル時間 870 ms
コンパイル使用メモリ 6,712 KB
実行使用メモリ 53,628 KB
最終ジャッジ日時 2023-09-26 08:11:51
合計ジャッジ時間 10,018 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
5,940 KB
testcase_01 AC 11 ms
5,968 KB
testcase_02 AC 11 ms
5,904 KB
testcase_03 AC 12 ms
6,048 KB
testcase_04 AC 12 ms
6,068 KB
testcase_05 AC 12 ms
6,156 KB
testcase_06 AC 12 ms
6,192 KB
testcase_07 AC 12 ms
6,084 KB
testcase_08 AC 12 ms
5,996 KB
testcase_09 AC 590 ms
29,216 KB
testcase_10 AC 613 ms
53,628 KB
testcase_11 AC 686 ms
36,684 KB
testcase_12 AC 687 ms
41,300 KB
testcase_13 AC 698 ms
39,520 KB
testcase_14 AC 677 ms
40,264 KB
testcase_15 AC 666 ms
37,960 KB
testcase_16 AC 670 ms
39,164 KB
testcase_17 AC 667 ms
38,928 KB
testcase_18 AC 644 ms
37,844 KB
testcase_19 AC 654 ms
38,472 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = input()
e = [[] for i in range(N)]
S = [N]*N
l = [(0,0)]
for i in range(N-1):
	x,y = map(int,raw_input().split())
	e[x-1]+=[y-1]
	e[y-1]+=[x-1]
for i in range(N):
	if len(e[i]) == 1:
		l+=[(i,i)]
d = 0
while l:
	nl = []
	for b,h in l:
		if d < S[h]:
			S[h] = d
			nl+=[(h,nxt) for nxt in e[h] if nxt != b]
	d+=1
	l = nl
for i in range(N):
	print S[i]
0