結果

問題 No.30 たこやき工場
ユーザー KudeKude
提出日時 2020-09-05 06:26:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 99 ms / 5,000 ms
コード長 578 bytes
コンパイル時間 281 ms
コンパイル使用メモリ 87,136 KB
実行使用メモリ 76,560 KB
最終ジャッジ日時 2023-08-23 05:23:32
合計ジャッジ時間 2,511 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,172 KB
testcase_01 AC 74 ms
71,208 KB
testcase_02 AC 75 ms
71,224 KB
testcase_03 AC 75 ms
71,016 KB
testcase_04 AC 71 ms
71,168 KB
testcase_05 AC 74 ms
70,712 KB
testcase_06 AC 74 ms
70,876 KB
testcase_07 AC 74 ms
70,864 KB
testcase_08 AC 75 ms
71,168 KB
testcase_09 AC 75 ms
71,080 KB
testcase_10 AC 99 ms
76,560 KB
testcase_11 AC 76 ms
71,020 KB
testcase_12 AC 74 ms
71,128 KB
testcase_13 AC 73 ms
71,208 KB
testcase_14 AC 76 ms
71,236 KB
testcase_15 AC 76 ms
71,140 KB
testcase_16 AC 78 ms
71,132 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
m = int(input())
to = [[] for _ in range(n)]
indegree = [0] * n
for _ in range(m):
    p, q, r = map(int, input().split())
    p -= 1
    r -= 1
    to[r].append((p, q))
    indegree[p] += 1
ans = [0] * (n - 1)
q = [i for i in range(n) if indegree[i] == 0]
required = [0] * n
required[n - 1] = 1
while q:
    u = q.pop()
    if not to[u]:
        ans[u] = required[u]
    else:
        for v, qv in to[u]:
            required[v] += qv * required[u]
            indegree[v] -= 1
            if indegree[v] == 0:
                q.append(v)
print(*ans, sep='\n')
0