結果

問題 No.806 木を道に
ユーザー 👑 horiesinitihoriesiniti
提出日時 2023-02-07 01:03:05
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 380 bytes
コンパイル時間 227 ms
コンパイル使用メモリ 11,240 KB
実行使用メモリ 27,240 KB
最終ジャッジ日時 2023-09-18 10:13:04
合計ジャッジ時間 6,422 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
15,076 KB
testcase_01 AC 80 ms
15,000 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 80 ms
15,200 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 82 ms
15,156 KB
testcase_08 AC 81 ms
15,252 KB
testcase_09 AC 81 ms
15,240 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 142 ms
17,544 KB
testcase_27 AC 277 ms
24,340 KB
testcase_28 AC 88 ms
15,524 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def f(n,u)
	res=[0]
	$gs[n].each{|u2|
		next if u==u2
		res<<f(u2,n)
	}
	if n==1 then
		res2=res.sort.reverse[0,2]
		ans=1
		case res2.size
		when 1
			ans=res2[0]
		else
			ans=res2.sum
		end
		return ans
	else
		
		return res.max+1
	end
end
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
}
puts n-1-f(1,-1)
0