結果

問題 No.277 根掘り葉掘り
ユーザー cielciel
提出日時 2015-10-14 14:02:29
言語 Ruby
(3.3.0)
結果
AC  
実行時間 1,346 ms / 3,000 ms
コード長 771 bytes
コンパイル時間 112 ms
コンパイル使用メモリ 11,516 KB
実行使用メモリ 167,768 KB
最終ジャッジ日時 2023-09-28 13:06:41
合計ジャッジ時間 15,525 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
外部呼び出し有り
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 166 ms
15,344 KB
testcase_01 AC 172 ms
15,280 KB
testcase_02 AC 170 ms
15,412 KB
testcase_03 AC 171 ms
15,380 KB
testcase_04 AC 173 ms
15,288 KB
testcase_05 AC 173 ms
15,404 KB
testcase_06 AC 174 ms
15,232 KB
testcase_07 AC 169 ms
15,268 KB
testcase_08 AC 167 ms
15,464 KB
testcase_09 AC 1,346 ms
167,768 KB
testcase_10 AC 1,024 ms
39,300 KB
testcase_11 AC 1,066 ms
33,332 KB
testcase_12 AC 1,265 ms
102,172 KB
testcase_13 AC 1,090 ms
35,172 KB
testcase_14 AC 1,082 ms
44,420 KB
testcase_15 AC 1,110 ms
51,276 KB
testcase_16 AC 1,112 ms
44,784 KB
testcase_17 AC 1,065 ms
44,012 KB
testcase_18 AC 1,062 ms
43,028 KB
testcase_19 AC 1,063 ms
41,620 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

if !ENV['RUBY_THREAD_VM_STACK_SIZE']
	require 'rubygems';RUBY=Gem.ruby
	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]}
0