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