結果

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

テストケース

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

ソースコード

diff #

#!/usr/bin/ruby
def dfs(n,d,z)
	r=nil
	H[n].each{|e|
		if !z.has_key?(e)
			z[e]=1
			r||=1<<29
			x=dfs(e,d+1,z)
			r=[r,x+1].min
			z.delete(e)
		end
	}
	r||=0
	R[n]=[r,d].min
	L[n]=r
	r
end
def dfs2(n,d,z)
	H[n].each{|e|
		if !z.has_key?(e)
			z[e]=1
			dfs2(e,[d,L[n]].min+1,z)
			z.delete(e)
		end
	}
	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