結果
問題 | No.30 たこやき工場 |
ユーザー |
![]() |
提出日時 | 2020-03-06 18:18:06 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 36 ms / 5,000 ms |
コード長 | 724 bytes |
コンパイル時間 | 179 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 10,880 KB |
最終ジャッジ日時 | 2024-12-21 05:29:46 |
合計ジャッジ時間 | 1,394 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 17 |
ソースコード
#!/usr/bin/env python3 # %% import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines # %% N = int(readline()) M = int(readline()) m = map(int, read().split()) PQR = zip(m, m, m) # %% graph = [[] for _ in range(N + 1)] in_deg = [0] * (N + 1) for p, q, r in PQR: graph[r].append((p, q)) in_deg[p] += 1 # %% dp = [0] * (N + 1) dp[N] = 1 stack = [i for i, x in enumerate(in_deg) if x == 0] while stack: v = stack.pop() if not graph[v]: continue for w, value in graph[v]: dp[w] += dp[v] * value in_deg[w] -= 1 if not in_deg[w]: stack.append(w) dp[v] = 0 # %% print('\n'.join(map(str, dp[1:-1])))