結果

問題 No.30 たこやき工場
ユーザー tnodinotnodino
提出日時 2022-02-13 15:40:58
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 20 ms / 5,000 ms
コード長 574 bytes
コンパイル時間 96 ms
コンパイル使用メモリ 10,956 KB
実行使用メモリ 8,404 KB
最終ジャッジ日時 2023-09-11 15:30:57
合計ジャッジ時間 1,543 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,836 KB
testcase_01 AC 16 ms
7,828 KB
testcase_02 AC 17 ms
7,832 KB
testcase_03 AC 17 ms
7,852 KB
testcase_04 AC 16 ms
7,916 KB
testcase_05 AC 16 ms
7,764 KB
testcase_06 AC 16 ms
7,824 KB
testcase_07 AC 17 ms
7,824 KB
testcase_08 AC 17 ms
7,764 KB
testcase_09 AC 17 ms
7,860 KB
testcase_10 AC 20 ms
8,404 KB
testcase_11 AC 17 ms
7,920 KB
testcase_12 AC 16 ms
7,984 KB
testcase_13 AC 17 ms
7,856 KB
testcase_14 AC 17 ms
7,832 KB
testcase_15 AC 17 ms
7,744 KB
testcase_16 AC 18 ms
7,892 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import setrecursionlimit
setrecursionlimit(10**6)
def dfs(pos):
    if cnt[pos] != -1:
        return cnt[pos]
    ret = 0
    for nxt,Q in G[pos]:
        ret += dfs(nxt) * Q
    cnt[pos] = ret
    return ret

N = int(input())
M = int(input())
G = [[] for _ in range(N)]
Rev = [True] * N
for _ in range(M):
    P,Q,R = map(int,input().split())
    P -= 1
    R -= 1
    G[P].append((R, Q))
    Rev[R] = False
cnt = [-1] * N
cnt[N-1] = 1
for i in range(N-1):
    if Rev[i]:
        dfs(i)
for i in range(N-1):
    if not Rev[i]:
        cnt[i] = 0
    print(cnt[i])
0