結果
問題 | No.277 根掘り葉掘り |
ユーザー | ciel |
提出日時 | 2015-10-14 14:06:53 |
言語 | Ruby (3.3.0) |
結果 |
AC
|
実行時間 | 1,224 ms / 3,000 ms |
コード長 | 739 bytes |
コンパイル時間 | 121 ms |
コンパイル使用メモリ | 11,312 KB |
実行使用メモリ | 167,712 KB |
最終ジャッジ日時 | 2023-09-28 13:06:57 |
合計ジャッジ時間 | 14,573 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge13 |
外部呼び出し有り |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 155 ms
15,272 KB |
testcase_01 | AC | 157 ms
15,428 KB |
testcase_02 | AC | 156 ms
15,348 KB |
testcase_03 | AC | 159 ms
15,232 KB |
testcase_04 | AC | 157 ms
15,400 KB |
testcase_05 | AC | 158 ms
15,392 KB |
testcase_06 | AC | 159 ms
15,348 KB |
testcase_07 | AC | 159 ms
15,280 KB |
testcase_08 | AC | 155 ms
15,280 KB |
testcase_09 | AC | 1,224 ms
167,712 KB |
testcase_10 | AC | 931 ms
39,512 KB |
testcase_11 | AC | 974 ms
33,504 KB |
testcase_12 | AC | 1,164 ms
102,300 KB |
testcase_13 | AC | 1,036 ms
34,872 KB |
testcase_14 | AC | 1,011 ms
44,508 KB |
testcase_15 | AC | 1,060 ms
51,084 KB |
testcase_16 | AC | 1,044 ms
44,612 KB |
testcase_17 | AC | 1,017 ms
44,008 KB |
testcase_18 | AC | 1,019 ms
42,920 KB |
testcase_19 | AC | 1,002 ms
41,580 KB |
コンパイルメッセージ
Syntax OK
ソースコード
if !ENV['RUBY_THREAD_VM_STACK_SIZE'] exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'ruby',$0,close_others:false) end def dfs(n,d,z) r=nil H[n].each{|e| if !z.has_key?(e) z[e]=1 r||=1<<29 x=dfs(e,d+1,z) r=[r,x+1].min z.delete(e) end } r||=0 R[n]=[r,d].min L[n]=r r end def dfs2(n,d,z) H[n].each{|e| if !z.has_key?(e) z[e]=1 dfs2(e,[d,L[n]].min+1,z) z.delete(e) end } R[n]=[R[n],d].min end n=gets.to_i H=Hash.new{|h,k|h[k]=[]} R={} L={} (n-1).times{ x,y=gets.split.map(&:to_i) H[x]<<y H[y]<<x } dfs(1,0,{1=>1}) dfs2(1,0,{1=>1}) 1.step(n){|i|p R[i]}