結果

問題 No.806 木を道に
ユーザー 👑 horiesinitihoriesiniti
提出日時 2023-02-07 01:39:03
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 539 bytes
コンパイル時間 79 ms
コンパイル使用メモリ 11,540 KB
実行使用メモリ 27,044 KB
最終ジャッジ日時 2023-09-18 10:40:14
合計ジャッジ時間 7,802 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
15,116 KB
testcase_01 AC 84 ms
15,272 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 83 ms
15,072 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 83 ms
15,152 KB
testcase_08 AC 82 ms
15,124 KB
testcase_09 AC 85 ms
14,968 KB
testcase_10 WA -
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 -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 RE -
testcase_25 RE -
testcase_26 AC 176 ms
18,124 KB
testcase_27 AC 376 ms
25,496 KB
testcase_28 AC 94 ms
15,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def f(n,u,c)
	res=[0]
	$gs[n].each{|u2|
		next if u==u2
		res<<f(u2,n,c+1)
	}
	res=res.sort.reverse[0,2]

	res2=[c]
	res3=[0]
	if res.size>0 then
		res3<<res.max
	end
	res<<c
	s1=res.size
	
	s1.times{|i|
		(i+1).upto(s1-1){|j|
			res2<<res[i]+res[j]
		}
	}
	#p [n,res,res2,res3]
	$dell=[$dell,res2.max].max
	return res3.max+1
end
$dell=0
n=gets.to_i
$gs=[]
(n+1).times{
	$gs<<[]
}

(n-1).times{|i|
	a,b=gets.split(" ").map{|e| e.to_i}
	$gs[a]<<b
	$gs[b]<<a
}
1.upto(n){|s|
	if $gs[s].size==1 then
		f(s,-1,0)
		break
	end
}
puts n-1-$dell
0