結果

問題 No.30 たこやき工場
ユーザー H3PO4H3PO4
提出日時 2020-04-20 11:06:16
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 784 bytes
コンパイル時間 88 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 17,564 KB
最終ジャッジ日時 2024-04-16 00:33:22
合計ジャッジ時間 7,519 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,752 KB
testcase_01 AC 32 ms
10,752 KB
testcase_02 AC 32 ms
10,624 KB
testcase_03 AC 31 ms
10,624 KB
testcase_04 AC 29 ms
10,752 KB
testcase_05 AC 30 ms
10,752 KB
testcase_06 AC 30 ms
10,496 KB
testcase_07 AC 30 ms
10,752 KB
testcase_08 AC 513 ms
10,752 KB
testcase_09 AC 31 ms
10,624 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())


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)
0