結果

問題 No.30 たこやき工場
ユーザー simansiman
提出日時 2021-08-12 18:31:58
言語 Ruby
(3.3.0)
結果
MLE  
実行時間 -
コード長 587 bytes
コンパイル時間 239 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 794,140 KB
最終ジャッジ日時 2024-04-09 22:25:09
合計ジャッジ時間 7,989 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
12,160 KB
testcase_01 AC 74 ms
12,416 KB
testcase_02 AC 72 ms
12,160 KB
testcase_03 AC 74 ms
12,160 KB
testcase_04 AC 77 ms
12,160 KB
testcase_05 AC 76 ms
12,288 KB
testcase_06 AC 76 ms
12,288 KB
testcase_07 AC 72 ms
12,160 KB
testcase_08 AC 296 ms
22,528 KB
testcase_09 AC 74 ms
12,288 KB
testcase_10 MLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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
visited_counter[N] = 1
queue = []
queue << [N, 1]

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

  need_ing[u] += b
  # next if visited_counter[u] > 0

  E[u].each do |v, cnt|
    queue << [v, cnt * b]
  end
end

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