結果

問題 No.30 たこやき工場
ユーザー 👑 rin204rin204
提出日時 2022-07-10 15:37:38
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 99 ms / 5,000 ms
コード長 585 bytes
コンパイル時間 454 ms
コンパイル使用メモリ 87,176 KB
実行使用メモリ 77,200 KB
最終ジャッジ日時 2023-09-01 22:05:12
合計ジャッジ時間 2,908 ms
ジャッジサーバーID
(参考情報)
judge12 / judge16
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,420 KB
testcase_01 AC 72 ms
71,336 KB
testcase_02 AC 73 ms
71,336 KB
testcase_03 AC 73 ms
71,444 KB
testcase_04 AC 75 ms
71,332 KB
testcase_05 AC 72 ms
71,064 KB
testcase_06 AC 71 ms
71,520 KB
testcase_07 AC 72 ms
71,520 KB
testcase_08 AC 73 ms
71,308 KB
testcase_09 AC 73 ms
71,228 KB
testcase_10 AC 99 ms
77,200 KB
testcase_11 AC 75 ms
71,304 KB
testcase_12 AC 73 ms
71,516 KB
testcase_13 AC 75 ms
71,340 KB
testcase_14 AC 76 ms
71,072 KB
testcase_15 AC 75 ms
71,228 KB
testcase_16 AC 77 ms
71,224 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
m = int(input())
in_ = [0] * n
edges = [[] for _ in range(n)]

for _ in range(m):
    p, q, r = map(int, input().split())
    p -= 1
    r -= 1
    in_[p] += 1
    edges[r].append((p, q))


stack = []
for i in range(n):
    if in_[i] == 0:
        stack.append(i)
dp = [0] * n
dp[n - 1] = 1
ans = [0] * n
while stack:
    pos = stack.pop()
    if len(edges[pos]) == 0:
        ans[pos] = dp[pos]
    for npos, c in edges[pos]:
        dp[npos] += dp[pos] * c
        in_[npos] -= 1
        if in_[npos] == 0:
            stack.append(npos)


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