結果

問題 No.30 たこやき工場
ユーザー H3PO4H3PO4
提出日時 2020-10-27 08:03:48
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 714 bytes
コンパイル時間 911 ms
コンパイル使用メモリ 86,816 KB
実行使用メモリ 83,084 KB
最終ジャッジ日時 2023-09-29 03:11:16
合計ジャッジ時間 9,140 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 101 ms
71,880 KB
testcase_01 AC 97 ms
71,752 KB
testcase_02 AC 97 ms
71,736 KB
testcase_03 AC 96 ms
71,388 KB
testcase_04 AC 96 ms
71,728 KB
testcase_05 AC 95 ms
71,812 KB
testcase_06 AC 96 ms
71,676 KB
testcase_07 AC 97 ms
71,740 KB
testcase_08 AC 331 ms
77,424 KB
testcase_09 AC 100 ms
72,424 KB
testcase_10 TLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

N = int(input())
M = int(input())

P = [{'no': n, 'parents': [], 'children': set(), 'items': 0} for n in range(N)]
P[N - 1]['items'] = 1

for _ in range(M):
    p, q, r = map(int, input().split())
    P[r - 1]['parents'].append((p - 1, q))
    P[p - 1]['children'].add(r - 1)

visited = set()

# dfs
d = deque([P[N - 1]])
while d:
    product = d.pop()
    if product['children'] <= visited:
        visited.add(product['no'])
        if product['parents']:
            for parent, q in product['parents']:
                P[parent]['items'] += q * product['items']
                d.append(P[parent])
            product['items'] = 0

for n in range(N - 1):
    print(P[n]['items'])
0