結果

問題 No.30 たこやき工場
ユーザー kohei2019
提出日時 2021-02-12 16:53:20
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 76 ms / 5,000 ms
コード長 502 bytes
コンパイル時間 281 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 68,992 KB
最終ジャッジ日時 2024-12-21 05:32:04
合計ジャッジ時間 1,821 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
M = int(input())
lsg = [[] for i in range(N)]
root = [True]*(N)
for i in range(M):
    p,q,r = map(int,input().split())
    p -= 1
    r -= 1
    lsg[p].append((r,q))
    root[r] = False
dp = [0]*(N)
dp[N-1] = 1
def dfs(k):
    if k == N-1:
        return 1
    if dp[k] != 0:
        return dp[k]
    cnt = 0
    for node,cost in lsg[k]:
        cnt += cost*dfs(node)
    dp[k] = cnt
    return cnt
for j in range(N-1):
    if root[j]:
        print(dfs(j))
    else:
        print(0)
0