結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 176 ms
16,232 KB
testcase_01 AC 174 ms
16,232 KB
testcase_02 AC 174 ms
16,232 KB
testcase_03 AC 172 ms
16,232 KB
testcase_04 AC 181 ms
16,536 KB
testcase_05 AC 222 ms
17,484 KB
testcase_06 AC 231 ms
17,552 KB
testcase_07 AC 204 ms
16,960 KB
testcase_08 AC 239 ms
17,772 KB
testcase_09 AC 227 ms
17,624 KB
testcase_10 AC 221 ms
17,552 KB
testcase_11 AC 215 ms
17,088 KB
testcase_12 AC 209 ms
17,008 KB
testcase_13 AC 171 ms
16,376 KB
testcase_14 AC 743 ms
29,304 KB
testcase_15 AC 719 ms
28,980 KB
testcase_16 AC 688 ms
28,660 KB
testcase_17 AC 553 ms
26,656 KB
testcase_18 AC 808 ms
33,324 KB
testcase_19 AC 918 ms
35,848 KB
testcase_20 AC 908 ms
35,844 KB
testcase_21 AC 912 ms
35,848 KB
testcase_22 AC 914 ms
35,856 KB
testcase_23 AC 913 ms
35,856 KB
testcase_24 AC 916 ms
35,848 KB
testcase_25 AC 914 ms
35,860 KB
testcase_26 AC 908 ms
35,848 KB
testcase_27 AC 914 ms
35,852 KB
testcase_28 AC 910 ms
35,852 KB
testcase_29 RE -
testcase_30 AC 1,249 ms
135,672 KB
testcase_31 AC 732 ms
33,568 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

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