結果

問題 No.30 たこやき工場
ユーザー mkawa2mkawa2
提出日時 2020-01-06 15:14:48
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 21 ms / 5,000 ms
コード長 712 bytes
コンパイル時間 86 ms
コンパイル使用メモリ 10,848 KB
実行使用メモリ 8,728 KB
最終ジャッジ日時 2023-08-23 05:21:28
合計ジャッジ時間 1,264 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,632 KB
testcase_01 AC 18 ms
8,640 KB
testcase_02 AC 19 ms
8,656 KB
testcase_03 AC 19 ms
8,528 KB
testcase_04 AC 19 ms
8,664 KB
testcase_05 AC 19 ms
8,708 KB
testcase_06 AC 19 ms
8,528 KB
testcase_07 AC 18 ms
8,628 KB
testcase_08 AC 19 ms
8,536 KB
testcase_09 AC 19 ms
8,696 KB
testcase_10 AC 21 ms
8,704 KB
testcase_11 AC 19 ms
8,536 KB
testcase_12 AC 18 ms
8,496 KB
testcase_13 AC 18 ms
8,720 KB
testcase_14 AC 19 ms
8,728 KB
testcase_15 AC 19 ms
8,548 KB
testcase_16 AC 19 ms
8,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10 ** 6)
from collections import *
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())

def main():
    def dfs(mi):
        dp[mi]=0
        for pi,cnt in mtop[mi]:
            if dp[pi]==-1:dfs(pi)
            dp[mi]+=dp[pi]*cnt

    n = II()
    m = II()
    mtop=defaultdict(list)
    buy=[True]*n
    for _ in range(m):
        material, cnt, product = MI()
        mtop[material-1].append([product-1,cnt])
        buy[product-1]=False

    dp = [-1] * n
    dp[n-1]=1
    for i in range(n-1):
        if dp[i]!=-1:continue
        dfs(i)

    for i in range(n-1):
        if buy[i]:print(dp[i])
        else:print(0)

main()
0