結果

問題 No.277 根掘り葉掘り
ユーザー cielciel
提出日時 2015-09-05 01:44:11
言語 PyPy2
(7.3.15)
結果
RE  
実行時間 -
コード長 619 bytes
コンパイル時間 2,054 ms
コンパイル使用メモリ 77,524 KB
実行使用メモリ 196,868 KB
最終ジャッジ日時 2023-09-26 08:25:34
合計ジャッジ時間 6,743 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
77,868 KB
testcase_01 AC 87 ms
78,172 KB
testcase_02 AC 93 ms
77,864 KB
testcase_03 AC 87 ms
77,888 KB
testcase_04 AC 85 ms
78,004 KB
testcase_05 AC 87 ms
78,068 KB
testcase_06 AC 85 ms
77,816 KB
testcase_07 AC 86 ms
78,000 KB
testcase_08 AC 84 ms
78,296 KB
testcase_09 RE -
testcase_10 AC 332 ms
117,764 KB
testcase_11 AC 518 ms
117,936 KB
testcase_12 RE -
testcase_13 AC 628 ms
116,724 KB
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 AC 542 ms
130,592 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/python
from collections import defaultdict
import sys
if sys.version_info[0]>=3: raw_input=input

def dfs(n,d,z):
	r=None
	for e in H[n]:
		if e not in z:
			z[e]=1
			if r is None: r=1<<29
			x=dfs(e,d+1,z)
			r=min(r,x+1)
			del z[e]
	if r is None: r=0
	R[n]=min(r,d)
	L[n]=r
	return r

def dfs2(n,d,z):
	for e in H[n]:
		if e not in z:
			z[e]=1
			dfs2(e,min(d,L[n])+1,z)
			del z[e]
	R[n]=min(R[n],d)

n=int(raw_input())
H=defaultdict(list)
R={}
L={}
for _ in range(n-1):
	x,y=map(int,raw_input().split())
	H[x].append(y)
	H[y].append(x)

dfs(1,0,{1:1})
dfs2(1,0,{1:1})
for i in range(1,n+1):print(R[i])
0