結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 86 ms
16,108 KB
testcase_01 AC 88 ms
16,108 KB
testcase_02 AC 89 ms
16,108 KB
testcase_03 AC 89 ms
16,104 KB
testcase_04 AC 103 ms
16,380 KB
testcase_05 AC 149 ms
17,196 KB
testcase_06 AC 151 ms
17,200 KB
testcase_07 AC 125 ms
16,752 KB
testcase_08 AC 164 ms
17,356 KB
testcase_09 AC 152 ms
17,340 KB
testcase_10 AC 149 ms
17,200 KB
testcase_11 AC 140 ms
17,184 KB
testcase_12 AC 132 ms
17,096 KB
testcase_13 AC 96 ms
16,220 KB
testcase_14 AC 726 ms
32,084 KB
testcase_15 AC 709 ms
28,820 KB
testcase_16 AC 667 ms
28,480 KB
testcase_17 AC 507 ms
24,576 KB
testcase_18 AC 774 ms
33,552 KB
testcase_19 AC 898 ms
34,396 KB
testcase_20 AC 904 ms
34,380 KB
testcase_21 AC 906 ms
34,388 KB
testcase_22 AC 905 ms
34,400 KB
testcase_23 AC 903 ms
34,396 KB
testcase_24 AC 911 ms
34,400 KB
testcase_25 AC 911 ms
34,404 KB
testcase_26 AC 909 ms
34,396 KB
testcase_27 AC 923 ms
34,400 KB
testcase_28 AC 919 ms
34,396 KB
testcase_29 RE -
testcase_30 RE -
testcase_31 AC 746 ms
32,176 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

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