結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
15,284 KB
testcase_01 AC 90 ms
15,148 KB
testcase_02 AC 86 ms
15,204 KB
testcase_03 AC 83 ms
15,228 KB
testcase_04 AC 86 ms
15,032 KB
testcase_05 WA -
testcase_06 AC 86 ms
15,148 KB
testcase_07 WA -
testcase_08 AC 84 ms
15,200 KB
testcase_09 WA -
testcase_10 AC 421 ms
20,332 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
P = Array.new(n+1,1)
R = Array.new(n+1,0)
L = Array.new(n+1,INF)

leaf = Array.new(n+1, true)
(n - 1).times do
    from, to = gets.split.map(&:to_i)
    P[to] = from
    R[to] = R[from] + 1
    leaf[from] = false
end

(1..n).select {|v| leaf[v]}.each do |i|
    d = R[i] + 1
    d.times.inject(i) do |j, dep|
        L[j] = [L[j], dep].min
        P[j]
    end
end

(1..n).each do |i|
  L[i] = [ L[i],L[P[i]] + 1].min
end

puts (1..n).map {|i| [R[i], L[i]].min }


0