結果

問題 No.277 根掘り葉掘り
ユーザー cielciel
提出日時 2015-10-14 13:36:48
言語 Ruby
(3.3.0)
結果
AC  
実行時間 1,297 ms / 3,000 ms
コード長 885 bytes
コンパイル時間 227 ms
コンパイル使用メモリ 11,168 KB
実行使用メモリ 167,800 KB
最終ジャッジ日時 2023-09-28 13:05:50
合計ジャッジ時間 15,258 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
外部呼び出し有り
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 170 ms
15,236 KB
testcase_01 AC 170 ms
15,112 KB
testcase_02 AC 167 ms
15,308 KB
testcase_03 AC 166 ms
15,304 KB
testcase_04 AC 167 ms
15,312 KB
testcase_05 AC 164 ms
15,284 KB
testcase_06 AC 173 ms
15,232 KB
testcase_07 AC 167 ms
15,296 KB
testcase_08 AC 164 ms
15,240 KB
testcase_09 AC 1,297 ms
167,800 KB
testcase_10 AC 981 ms
39,532 KB
testcase_11 AC 1,043 ms
34,508 KB
testcase_12 AC 1,180 ms
102,368 KB
testcase_13 AC 1,049 ms
35,200 KB
testcase_14 AC 1,044 ms
44,528 KB
testcase_15 AC 1,050 ms
51,240 KB
testcase_16 AC 1,053 ms
44,792 KB
testcase_17 AC 1,035 ms
43,996 KB
testcase_18 AC 1,037 ms
43,052 KB
testcase_19 AC 1,036 ms
41,692 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

#!/usr/bin/ruby
if !ENV['RUBY_THREAD_VM_STACK_SIZE']
	#require 'rbconfig';RUBY=File.join(RbConfig::CONFIG['bindir'],RbConfig::CONFIG['ruby_install_name'])
	require 'rubygems';RUBY=Gem.ruby
	system('RUBY_THREAD_VM_STACK_SIZE=100000000 "'+RUBY+'" "'+$0+'"')
	exit
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