結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
15,184 KB
testcase_01 AC 84 ms
14,996 KB
testcase_02 AC 80 ms
15,260 KB
testcase_03 AC 80 ms
15,176 KB
testcase_04 AC 81 ms
14,996 KB
testcase_05 AC 81 ms
15,052 KB
testcase_06 AC 81 ms
15,148 KB
testcase_07 WA -
testcase_08 AC 79 ms
15,040 KB
testcase_09 WA -
testcase_10 AC 705 ms
39,000 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,[d,L[n]].min+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