結果

問題 No.30 たこやき工場
コンテスト
ユーザー tktk_snsn
提出日時 2020-12-13 02:30:15
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
WA  
実行時間 -
コード長 660 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 170 ms
コンパイル使用メモリ 85,316 KB
実行使用メモリ 64,200 KB
最終ジャッジ日時 2026-04-08 11:47:00
合計ジャッジ時間 1,727 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 6 WA * 11
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from collections import deque
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

N = int(input())
M = int(input())
out = [0] * N
parent = [[] for _ in range(N)]
for _ in range(M):
    s, c, t = map(int, input().split())
    s -= 1
    t -= 1
    out[s] += 1
    parent[t].append((s, c))


cnt = [0] * N
que = deque()
for i, o in enumerate(out):
    if not o:
        cnt[i] = 1
        que.append(i)

while que:
    s = que.popleft()
    d = cnt[s]
    for t, c in parent[s]:
        cnt[t] += c * d
        out[t] -= 1
        if out[t] == 0:
            que.append(t)
    if parent[s]:
        cnt[s] = 0

print(*cnt[:-1], sep="\n")
0