結果

問題 No.30 たこやき工場
ユーザー simansiman
提出日時 2021-08-12 15:48:26
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 538 bytes
コンパイル時間 42 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 12,416 KB
最終ジャッジ日時 2024-04-09 20:16:28
合計ジャッジ時間 2,361 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
12,160 KB
testcase_01 AC 82 ms
12,160 KB
testcase_02 AC 92 ms
12,160 KB
testcase_03 AC 87 ms
12,160 KB
testcase_04 AC 81 ms
12,288 KB
testcase_05 AC 78 ms
12,160 KB
testcase_06 AC 77 ms
12,288 KB
testcase_07 AC 83 ms
12,160 KB
testcase_08 AC 85 ms
12,160 KB
testcase_09 AC 84 ms
12,160 KB
testcase_10 AC 88 ms
12,288 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N = gets.to_i
M = gets.to_i
E = Hash.new { |h, k| h[k] = {} }
visited_counter = Array.new(N + 1, 0)

M.times do
  u, c, v = gets.split.map(&:to_i)

  visited_counter[u] += 1
  E[v][u] = c
end

need_ing = Array.new(N + 1, 0)
need_ing[N] = 1
queue = []
queue << N

until queue.empty?
  u = queue.shift
  visited_counter[u] -= 1

  next if visited_counter[u] > 0

  E[u].each do |v, cnt|
    need_ing[v] += cnt * need_ing[u]
    queue << v
  end
end

1.upto(N - 1) do |v|
  if E[v].size == 0
    puts need_ing[v]
  else
    puts 0
  end
end
0