結果

問題 No.30 たこやき工場
ユーザー lloyzlloyz
提出日時 2023-08-27 14:40:35
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 786 bytes
コンパイル時間 258 ms
コンパイル使用メモリ 86,888 KB
実行使用メモリ 77,612 KB
最終ジャッジ日時 2023-08-27 14:40:38
合計ジャッジ時間 2,921 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 94 ms
71,412 KB
testcase_01 AC 93 ms
71,416 KB
testcase_02 AC 93 ms
71,676 KB
testcase_03 AC 98 ms
71,696 KB
testcase_04 AC 94 ms
71,720 KB
testcase_05 AC 93 ms
71,456 KB
testcase_06 AC 94 ms
71,672 KB
testcase_07 AC 94 ms
71,752 KB
testcase_08 AC 96 ms
71,420 KB
testcase_09 AC 104 ms
76,544 KB
testcase_10 AC 150 ms
77,612 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict, deque

n = int(input())
m = int(input())
G = defaultdict(list)
INcnt = [0 for _ in range(n)]
for _ in range(m):
    p, q, r = map(int, input().split())
    G[r - 1].append((p - 1, q))
    INcnt[p - 1] += 1

ANS = [0 for _ in range(n - 1)]
C = [[0 for _ in range(n)] for _ in range(n)]
Que = deque()
for i in range(n):
    if INcnt[i] == 0:
        C[i][i] = 1
        Que.append((i, i))
while Que:
    cp, f = Que.popleft()
    cnt = C[f][cp]
    if len(G[cp]) == 0 and f == n - 1:
        ANS[cp] = cnt
        continue
    for np, q in G[cp]:
        C[f][np] += cnt * q
        INcnt[np] -= 1
        if INcnt[np] == 0:
            for i in range(n):
                if C[i][np] > 0:
                    Que.append((np, i))
print(*ANS, sep='\n')
0