結果

問題 No.30 たこやき工場
ユーザー rlangevinrlangevin
提出日時 2023-09-12 08:58:27
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 186 ms / 5,000 ms
コード長 563 bytes
コンパイル時間 329 ms
コンパイル使用メモリ 86,520 KB
実行使用メモリ 77,800 KB
最終ジャッジ日時 2023-09-12 08:58:30
合計ジャッジ時間 3,198 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 94 ms
71,548 KB
testcase_01 AC 93 ms
71,508 KB
testcase_02 AC 97 ms
71,500 KB
testcase_03 AC 93 ms
71,380 KB
testcase_04 AC 98 ms
71,388 KB
testcase_05 AC 95 ms
71,500 KB
testcase_06 AC 95 ms
71,520 KB
testcase_07 AC 95 ms
71,192 KB
testcase_08 AC 97 ms
71,452 KB
testcase_09 AC 103 ms
72,192 KB
testcase_10 AC 186 ms
77,800 KB
testcase_11 AC 95 ms
71,272 KB
testcase_12 AC 93 ms
71,536 KB
testcase_13 AC 101 ms
71,408 KB
testcase_14 AC 96 ms
72,212 KB
testcase_15 AC 97 ms
72,248 KB
testcase_16 AC 99 ms
72,176 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import *

N = int(input())
M = int(input())
G = [[] for i in range(N)]
deg = [0] * N
for i in range(M):
    p, q, r = map(int, input().split())
    p, r = p - 1, r - 1
    G[r].append((p, q))
    deg[p] += 1

Q = deque()
for i in range(N):
    if deg[i] == 0:
        Q.append(i)

ans = [0] * N
ans[-1] = 1
while Q:
    u = Q.popleft()
    for v, c in G[u]:
        ans[v] += ans[u] * c
        deg[v] -= 1
        if deg[v] == 0:
            Q.append(v)
            
    if len(G[u]):
        ans[u] = 0

for i in range(N - 1):
    print(ans[i])
0