結果

問題 No.30 たこやき工場
ユーザー ああいいああいい
提出日時 2022-03-02 15:13:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 129 ms / 5,000 ms
コード長 717 bytes
コンパイル時間 414 ms
コンパイル使用メモリ 86,872 KB
実行使用メモリ 79,368 KB
最終ジャッジ日時 2023-09-23 08:19:34
合計ジャッジ時間 3,401 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 94 ms
71,376 KB
testcase_01 AC 95 ms
71,508 KB
testcase_02 AC 94 ms
71,512 KB
testcase_03 AC 96 ms
71,464 KB
testcase_04 AC 94 ms
71,376 KB
testcase_05 AC 95 ms
71,456 KB
testcase_06 AC 96 ms
71,532 KB
testcase_07 AC 96 ms
71,200 KB
testcase_08 AC 97 ms
71,536 KB
testcase_09 AC 101 ms
72,096 KB
testcase_10 AC 129 ms
79,368 KB
testcase_11 AC 96 ms
71,732 KB
testcase_12 AC 94 ms
71,376 KB
testcase_13 AC 95 ms
71,316 KB
testcase_14 AC 102 ms
72,152 KB
testcase_15 AC 100 ms
72,112 KB
testcase_16 AC 105 ms
72,200 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
M = int(input())
G = [[] for _ in range(N+1)]
rG = [[] for _ in range(N+1)]
Gnum = [0] * (N + 1)
for _ in range(M):
    p,q,r = map(int,input().split())
    G[p].append(r)
    rG[r].append((p,q))
    Gnum[r] += 1
top = []
gaibu = set()
from collections import deque
q = deque()
for i in range(1,N+1):
    if Gnum[i] == 0:
        q.append(i)
        gaibu.add(i)
while q:
    now = q.popleft()
    top.append(now)
    for v in G[now]:
        Gnum[v] -= 1
        if Gnum[v] == 0:
            q.append(v)
dp = [0] * (N+1)
dp[N] = 1
for now in reversed(top):
    for v,c in rG[now]:
        dp[v] += dp[now] * c
for i in range(1,N):
    if i in gaibu:
        print(dp[i])
    else:
        print(0)

0