結果

問題 No.1484 木に数を書き込む問題 / Just Write Numbers! 2
ユーザー cielciel
提出日時 2021-05-12 02:40:10
言語 Crystal
(1.11.2)
結果
AC  
実行時間 465 ms / 2,000 ms
コード長 298 bytes
コンパイル時間 18,121 ms
コンパイル使用メモリ 292,156 KB
実行使用メモリ 76,908 KB
最終ジャッジ日時 2023-10-22 07:38:19
合計ジャッジ時間 26,983 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,324 KB
testcase_01 AC 2 ms
4,328 KB
testcase_02 AC 2 ms
4,328 KB
testcase_03 AC 1 ms
4,328 KB
testcase_04 AC 6 ms
4,328 KB
testcase_05 AC 20 ms
5,212 KB
testcase_06 AC 22 ms
5,208 KB
testcase_07 AC 13 ms
4,440 KB
testcase_08 AC 25 ms
6,008 KB
testcase_09 AC 23 ms
5,208 KB
testcase_10 AC 21 ms
5,208 KB
testcase_11 AC 18 ms
5,212 KB
testcase_12 AC 16 ms
4,980 KB
testcase_13 AC 3 ms
4,328 KB
testcase_14 AC 344 ms
23,084 KB
testcase_15 AC 339 ms
20,944 KB
testcase_16 AC 299 ms
20,944 KB
testcase_17 AC 225 ms
16,396 KB
testcase_18 AC 409 ms
23,172 KB
testcase_19 AC 450 ms
29,860 KB
testcase_20 AC 447 ms
29,860 KB
testcase_21 AC 441 ms
29,860 KB
testcase_22 AC 435 ms
29,860 KB
testcase_23 AC 437 ms
29,860 KB
testcase_24 AC 438 ms
29,860 KB
testcase_25 AC 438 ms
29,860 KB
testcase_26 AC 442 ms
29,860 KB
testcase_27 AC 447 ms
29,860 KB
testcase_28 AC 465 ms
29,860 KB
testcase_29 AC 268 ms
76,908 KB
testcase_30 AC 287 ms
46,668 KB
testcase_31 AC 210 ms
30,664 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
0