結果

問題 No.1484 木に数を書き込む問題 / Just Write Numbers! 2
ユーザー cielciel
提出日時 2021-05-12 02:27:01
言語 Ruby
(3.3.0)
結果
RE  
実行時間 -
コード長 263 bytes
コンパイル時間 76 ms
コンパイル使用メモリ 11,916 KB
実行使用メモリ 34,404 KB
最終ジャッジ日時 2023-10-22 07:23:34
合計ジャッジ時間 18,579 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
16,092 KB
testcase_01 AC 89 ms
16,092 KB
testcase_02 AC 86 ms
16,092 KB
testcase_03 AC 83 ms
16,092 KB
testcase_04 AC 97 ms
16,368 KB
testcase_05 AC 140 ms
17,372 KB
testcase_06 AC 139 ms
17,440 KB
testcase_07 AC 115 ms
16,840 KB
testcase_08 AC 149 ms
17,684 KB
testcase_09 AC 143 ms
17,508 KB
testcase_10 AC 137 ms
17,440 KB
testcase_11 AC 132 ms
16,976 KB
testcase_12 AC 123 ms
16,896 KB
testcase_13 AC 89 ms
16,216 KB
testcase_14 AC 645 ms
31,380 KB
testcase_15 AC 625 ms
30,712 KB
testcase_16 AC 587 ms
29,676 KB
testcase_17 AC 470 ms
25,648 KB
testcase_18 AC 726 ms
32,008 KB
testcase_19 AC 823 ms
32,836 KB
testcase_20 AC 820 ms
32,820 KB
testcase_21 AC 827 ms
32,828 KB
testcase_22 AC 828 ms
32,840 KB
testcase_23 AC 828 ms
32,832 KB
testcase_24 AC 823 ms
32,828 KB
testcase_25 AC 827 ms
32,840 KB
testcase_26 AC 817 ms
32,836 KB
testcase_27 AC 818 ms
32,836 KB
testcase_28 AC 811 ms
32,832 KB
testcase_29 RE -
testcase_30 RE -
testcase_31 AC 653 ms
30,620 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def dfs(z,c)
	f=1
	r=[0,c]
	G[c].each{|e|
		next if e==z
		t=dfs(c,e)
		r=[r,[t[0]+f,t[1]]].max
	}
	r
end
def diameter
	dfs(-1,dfs(-1,0)[1])[0]
end
N=gets.to_i
G=N.times.map{[]}
(N-1).times{
	a,b=gets.split.map(&:to_i)
	G[a-1]<<b-1
	G[b-1]<<a-1
}
p 2*~-N-diameter
0