結果

問題 No.277 根掘り葉掘り
ユーザー cielciel
提出日時 2015-09-05 01:28:09
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 353 bytes
コンパイル時間 68 ms
コンパイル使用メモリ 11,524 KB
実行使用メモリ 39,148 KB
最終ジャッジ日時 2023-09-26 08:13:07
合計ジャッジ時間 8,888 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
15,224 KB
testcase_01 AC 86 ms
15,192 KB
testcase_02 AC 80 ms
15,108 KB
testcase_03 AC 83 ms
15,160 KB
testcase_04 AC 82 ms
15,096 KB
testcase_05 AC 82 ms
15,264 KB
testcase_06 AC 82 ms
15,052 KB
testcase_07 WA -
testcase_08 AC 80 ms
15,048 KB
testcase_09 WA -
testcase_10 AC 684 ms
39,148 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

#!/usr/bin/ruby
def dfs(n,d)
	r=nil
	H[n].each{|e|
		r||=1<<29
		x=dfs(e,d+1)
		r=[r,x+1].min
	}
	r||=0
	R[n]=[r,d].min
	L[n]=r
	r
end
def dfs2(n,d)
	H[n].each{|e|dfs2(e,L[n]+1)}
	R[n]=[R[n],d].min
end
		
n=gets.to_i
H=Hash.new{|h,k|h[k]=[]}
R={}
L={}
(n-1).times{
	x,y=gets.split.map(&:to_i)
	H[x]<<y
	#H[y]<<x
}
dfs(1,0)
dfs2(1,0)
1.step(n){|i|p R[i]}
0