結果
| 問題 |
No.806 木を道に
|
| コンテスト | |
| ユーザー |
horiesiniti
|
| 提出日時 | 2023-02-07 01:03:05 |
| 言語 | Ruby (3.4.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 380 bytes |
| コンパイル時間 | 131 ms |
| コンパイル使用メモリ | 7,296 KB |
| 実行使用メモリ | 24,064 KB |
| 最終ジャッジ日時 | 2024-07-05 01:51:36 |
| 合計ジャッジ時間 | 7,287 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 7 WA * 18 RE * 2 |
コンパイルメッセージ
Syntax OK
ソースコード
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)
horiesiniti