結果

問題 No.277 根掘り葉掘り
ユーザー TANIGUCHI KousukeTANIGUCHI Kousuke
提出日時 2015-09-08 22:58:08
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 494 bytes
コンパイル時間 177 ms
コンパイル使用メモリ 11,520 KB
実行使用メモリ 20,028 KB
最終ジャッジ日時 2023-09-26 10:10:58
合計ジャッジ時間 6,416 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
15,048 KB
testcase_01 AC 82 ms
15,280 KB
testcase_02 WA -
testcase_03 AC 81 ms
15,108 KB
testcase_04 AC 82 ms
15,220 KB
testcase_05 WA -
testcase_06 AC 82 ms
15,132 KB
testcase_07 WA -
testcase_08 AC 82 ms
15,136 KB
testcase_09 WA -
testcase_10 AC 396 ms
20,028 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

# Here your code !
INF = 10 ** 8
n = gets.to_i
parent = Array.new(n+1,1)
depth = Array.new(n+1,0)
foot = Array.new(n+1,INF)
leaf = Array.new(n+1,true)
(n - 1).times do
    from, to = gets.split.map(&:to_i)
    parent[to] = from
    depth[to] = depth[from] + 1
    leaf[from] = false
end
(1..n).select {|v| leaf[v]}.each do |i|
    d = depth[i]
    d.times.inject(i) do |j, dep|
        foot[j] = [foot[j], dep].min
        parent[j]
    end
end

puts (1..n).map {|i| [depth[i], foot[i]].min }

0