結果
| 問題 | No.30 たこやき工場 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2020-04-20 11:06:16 | 
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) | 
| 結果 | 
                                TLE
                                 
                             | 
| 実行時間 | - | 
| コード長 | 784 bytes | 
| コンパイル時間 | 219 ms | 
| コンパイル使用メモリ | 12,672 KB | 
| 実行使用メモリ | 17,572 KB | 
| 最終ジャッジ日時 | 2024-10-06 08:33:34 | 
| 合計ジャッジ時間 | 7,590 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 10 TLE * 1 -- * 6 | 
ソースコード
from collections import deque
N = int(input())
M = int(input())
class Product:
    def __init__(self, no):
        self.no = no
        self.parents = []
        self.children = set()
        self.items = 0
P = [Product(n) 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)
            
            
            
        