結果

問題 No.30 たこやき工場
ユーザー kohei2019kohei2019
提出日時 2021-02-12 16:53:20
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 99 ms / 5,000 ms
コード長 502 bytes
コンパイル時間 275 ms
コンパイル使用メモリ 87,152 KB
実行使用メモリ 76,628 KB
最終ジャッジ日時 2023-08-23 05:23:56
合計ジャッジ時間 2,490 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,144 KB
testcase_01 AC 72 ms
71,300 KB
testcase_02 AC 71 ms
71,116 KB
testcase_03 AC 71 ms
71,120 KB
testcase_04 AC 75 ms
71,148 KB
testcase_05 AC 70 ms
71,176 KB
testcase_06 AC 72 ms
71,140 KB
testcase_07 AC 70 ms
71,180 KB
testcase_08 AC 74 ms
71,180 KB
testcase_09 AC 75 ms
71,240 KB
testcase_10 AC 99 ms
76,628 KB
testcase_11 AC 74 ms
71,296 KB
testcase_12 AC 71 ms
71,244 KB
testcase_13 AC 73 ms
70,976 KB
testcase_14 AC 88 ms
75,388 KB
testcase_15 AC 77 ms
70,972 KB
testcase_16 AC 89 ms
75,656 KB
権限があれば一括ダウンロードができます

ソースコード

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