結果

問題 No.277 根掘り葉掘り
ユーザー TawaraTawara
提出日時 2015-09-05 01:27:08
言語 PyPy2
(7.3.15)
結果
AC  
実行時間 339 ms / 3,000 ms
コード長 355 bytes
コンパイル時間 1,492 ms
コンパイル使用メモリ 77,904 KB
実行使用メモリ 120,132 KB
最終ジャッジ日時 2023-09-26 08:12:56
合計ジャッジ時間 7,073 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
76,268 KB
testcase_01 AC 72 ms
76,396 KB
testcase_02 AC 74 ms
76,568 KB
testcase_03 AC 74 ms
76,392 KB
testcase_04 AC 75 ms
76,424 KB
testcase_05 AC 75 ms
76,392 KB
testcase_06 AC 75 ms
76,612 KB
testcase_07 AC 76 ms
76,356 KB
testcase_08 AC 75 ms
76,404 KB
testcase_09 AC 315 ms
92,540 KB
testcase_10 AC 288 ms
120,132 KB
testcase_11 AC 315 ms
99,344 KB
testcase_12 AC 315 ms
103,552 KB
testcase_13 AC 339 ms
102,436 KB
testcase_14 AC 308 ms
101,820 KB
testcase_15 AC 317 ms
100,492 KB
testcase_16 AC 323 ms
100,548 KB
testcase_17 AC 306 ms
100,848 KB
testcase_18 AC 315 ms
100,116 KB
testcase_19 AC 306 ms
100,104 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