結果
| 問題 |
No.1484 木に数を書き込む問題 / Just Write Numbers! 2
|
| ユーザー |
|
| 提出日時 | 2021-05-12 02:40:00 |
| 言語 | Ruby (3.4.1) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 298 bytes |
| コンパイル時間 | 146 ms |
| コンパイル使用メモリ | 7,552 KB |
| 実行使用メモリ | 31,744 KB |
| 最終ジャッジ日時 | 2024-09-22 08:42:35 |
| 合計ジャッジ時間 | 17,430 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 RE * 2 |
コンパイルメッセージ
Syntax OK
ソースコード
def dfs(g,z,c)
f=1
r=[0,c]
g[c].each{|e|
next if e==z
t=dfs(g,c,e)
r=[r,[t[0]+f,t[1]]].max
}
r
end
def diameter(g)
dfs(g,-1,dfs(g,-1,0)[1])[0]
end
n=gets.to_s.to_i
g=n.times.map{[0]*0}.to_a
(n-1).times{
a,b=gets.to_s.split.map{|e|e.to_i}
g[a-1]<<b-1
g[b-1]<<a-1
}
p 2*~-n-diameter(g)