結果

問題 No.30 たこやき工場
ユーザー tktk_snsntktk_snsn
提出日時 2020-12-13 02:30:15
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 660 bytes
コンパイル時間 179 ms
コンパイル使用メモリ 81,824 KB
実行使用メモリ 64,196 KB
最終ジャッジ日時 2023-10-20 02:55:48
合計ジャッジ時間 2,045 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
55,428 KB
testcase_01 AC 41 ms
55,428 KB
testcase_02 WA -
testcase_03 AC 41 ms
55,428 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 41 ms
55,428 KB
testcase_09 AC 41 ms
55,428 KB
testcase_10 AC 52 ms
64,196 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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