結果
問題 | No.30 たこやき工場 |
ユーザー | sotanishy |
提出日時 | 2021-08-09 13:29:04 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 57 ms / 5,000 ms |
コード長 | 940 bytes |
コンパイル時間 | 1,570 ms |
コンパイル使用メモリ | 81,264 KB |
実行使用メモリ | 64,148 KB |
最終ジャッジ日時 | 2023-10-21 11:14:26 |
合計ジャッジ時間 | 2,142 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge10 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 38 ms
53,116 KB |
testcase_01 | AC | 38 ms
53,116 KB |
testcase_02 | AC | 39 ms
53,116 KB |
testcase_03 | AC | 38 ms
53,116 KB |
testcase_04 | AC | 38 ms
53,116 KB |
testcase_05 | AC | 38 ms
53,116 KB |
testcase_06 | AC | 38 ms
53,116 KB |
testcase_07 | AC | 39 ms
53,116 KB |
testcase_08 | AC | 39 ms
53,116 KB |
testcase_09 | AC | 40 ms
53,116 KB |
testcase_10 | AC | 57 ms
64,148 KB |
testcase_11 | AC | 39 ms
53,232 KB |
testcase_12 | AC | 39 ms
53,232 KB |
testcase_13 | AC | 38 ms
53,232 KB |
testcase_14 | AC | 39 ms
53,232 KB |
testcase_15 | AC | 40 ms
53,232 KB |
testcase_16 | AC | 39 ms
53,232 KB |
ソースコード
import sys input = sys.stdin.readline def topological_sort(G): ret = [] start = [] par_count = [0] * len(G) for u in range(len(G)): for v, _ in G[u]: par_count[v] += 1 for v in range(len(G)): if par_count[v] == 0: start.append(v) while start: u = start.pop() ret.append(u) for v, _ in G[u]: par_count[v] -= 1 if par_count[v] == 0: start.append(v) if any(c > 0 for c in par_count): # G is not a DAG return None return ret N = int(input()) M = int(input()) G = [[] for _ in range(N)] for _ in range(M): P, Q, R = map(int, input().split()) P -= 1 R -= 1 G[R].append((P, Q)) order = topological_sort(G) ans = [0] * N ans[N-1] = 1 for v in order: if not G[v]: continue for u, c in G[v]: ans[u] += ans[v] * c ans[v] = 0 print(*ans[:-1], sep='\n')