結果

問題 No.1484 木に数を書き込む問題 / Just Write Numbers! 2
ユーザー cielciel
提出日時 2021-05-12 02:29:12
言語 Ruby
(3.3.0)
結果
RE  
実行時間 -
コード長 325 bytes
コンパイル時間 131 ms
コンパイル使用メモリ 11,844 KB
実行使用メモリ 59,124 KB
最終ジャッジ日時 2023-10-22 07:25:34
合計ジャッジ時間 19,696 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 169 ms
16,124 KB
testcase_01 AC 169 ms
16,124 KB
testcase_02 AC 170 ms
16,124 KB
testcase_03 AC 166 ms
16,124 KB
testcase_04 AC 179 ms
16,304 KB
testcase_05 AC 217 ms
17,300 KB
testcase_06 AC 223 ms
17,372 KB
testcase_07 AC 201 ms
16,776 KB
testcase_08 AC 232 ms
17,624 KB
testcase_09 AC 223 ms
17,440 KB
testcase_10 AC 219 ms
17,372 KB
testcase_11 AC 213 ms
16,900 KB
testcase_12 AC 211 ms
16,824 KB
testcase_13 AC 175 ms
16,152 KB
testcase_14 AC 732 ms
31,384 KB
testcase_15 AC 702 ms
30,652 KB
testcase_16 AC 664 ms
29,616 KB
testcase_17 AC 538 ms
25,584 KB
testcase_18 AC 787 ms
31,952 KB
testcase_19 AC 892 ms
32,776 KB
testcase_20 AC 893 ms
32,760 KB
testcase_21 AC 884 ms
32,768 KB
testcase_22 AC 883 ms
32,780 KB
testcase_23 AC 882 ms
32,772 KB
testcase_24 AC 878 ms
32,768 KB
testcase_25 AC 877 ms
32,780 KB
testcase_26 AC 884 ms
32,780 KB
testcase_27 AC 887 ms
32,776 KB
testcase_28 AC 886 ms
32,772 KB
testcase_29 RE -
testcase_30 RE -
testcase_31 AC 734 ms
30,628 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

ENV[Z='RUBY_THREAD_VM_STACK_SIZE']||exec({Z=>?5*7},'ruby',$0)
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