結果
問題 | No.1364 [Renaming] Road to Cherry from Zelkova |
ユーザー | rlangevin |
提出日時 | 2024-01-08 01:29:32 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,479 bytes |
コンパイル時間 | 259 ms |
コンパイル使用メモリ | 82,368 KB |
実行使用メモリ | 158,124 KB |
最終ジャッジ日時 | 2024-09-27 19:34:17 |
合計ジャッジ時間 | 12,869 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 38 ms
54,144 KB |
testcase_01 | AC | 39 ms
54,304 KB |
testcase_02 | AC | 39 ms
54,828 KB |
testcase_03 | AC | 40 ms
54,936 KB |
testcase_04 | AC | 40 ms
56,104 KB |
testcase_05 | AC | 37 ms
55,004 KB |
testcase_06 | AC | 37 ms
54,820 KB |
testcase_07 | AC | 39 ms
54,580 KB |
testcase_08 | AC | 92 ms
79,540 KB |
testcase_09 | AC | 78 ms
78,144 KB |
testcase_10 | AC | 96 ms
78,628 KB |
testcase_11 | AC | 96 ms
79,172 KB |
testcase_12 | AC | 88 ms
78,504 KB |
testcase_13 | AC | 379 ms
131,668 KB |
testcase_14 | AC | 449 ms
141,572 KB |
testcase_15 | AC | 418 ms
143,276 KB |
testcase_16 | AC | 291 ms
123,056 KB |
testcase_17 | AC | 188 ms
103,744 KB |
testcase_18 | AC | 483 ms
156,708 KB |
testcase_19 | AC | 494 ms
157,988 KB |
testcase_20 | AC | 488 ms
157,728 KB |
testcase_21 | AC | 513 ms
157,080 KB |
testcase_22 | AC | 536 ms
158,124 KB |
testcase_23 | AC | 154 ms
96,312 KB |
testcase_24 | AC | 102 ms
84,976 KB |
testcase_25 | AC | 217 ms
102,612 KB |
testcase_26 | AC | 344 ms
134,372 KB |
testcase_27 | AC | 251 ms
120,960 KB |
testcase_28 | AC | 171 ms
94,644 KB |
testcase_29 | AC | 230 ms
109,864 KB |
testcase_30 | AC | 167 ms
93,536 KB |
testcase_31 | AC | 168 ms
99,436 KB |
testcase_32 | AC | 190 ms
113,300 KB |
testcase_33 | AC | 283 ms
120,788 KB |
testcase_34 | AC | 327 ms
128,328 KB |
testcase_35 | WA | - |
testcase_36 | AC | 219 ms
116,048 KB |
testcase_37 | AC | 171 ms
105,408 KB |
testcase_38 | AC | 256 ms
137,848 KB |
testcase_39 | AC | 263 ms
137,696 KB |
testcase_40 | AC | 268 ms
137,568 KB |
testcase_41 | AC | 266 ms
137,936 KB |
testcase_42 | AC | 298 ms
137,952 KB |
testcase_43 | AC | 189 ms
124,604 KB |
testcase_44 | AC | 162 ms
112,668 KB |
testcase_45 | AC | 182 ms
118,924 KB |
testcase_46 | AC | 62 ms
83,864 KB |
testcase_47 | AC | 37 ms
54,364 KB |
ソースコード
import sys input = sys.stdin.readline from collections import deque def topsort(G): Q = deque() N = len(G) count = [0] * N for u in range(N): for v, _, _ in G[u]: count[v] += 1 for u in range(N): if count[u] == 0: Q.append(u) anslst = [] while Q: u = Q.pop() anslst.append(u) for v, _, _ in G[u]: count[v] -= 1 if count[v] == 0: Q.append(v) return anslst def bfs(G, s): Q = deque([s]) N = len(G) dist = [-1] * N par = [-1] * N dist[s] = 0 while Q: u = Q.popleft() for v in G[u]: if dist[v] != -1: continue dist[v] = dist[u] + 1 par[v] = u Q.append(v) return dist N, M = map(int, input().split()) G = [[] for i in range(N + 1)] Gr = [[] for i in range(N + 1)] D = [] for i in range(M): u, v, l, a = list(map(int, input().split())) D.append([u, v, l, a]) Gr[v].append(u) dist = bfs(Gr, N) for u, v, l, a in D: if dist[u] == -1 or dist[v] == -1: continue G[u].append((v, l, a)) dp = [0] * (N + 1) dp_sum = [0] * (N + 1) dp[0] = 1 L = topsort(G) if len(L) != N + 1: print("INF") exit() mod = 10**9 + 7 for u in L: for v, l, a in G[u]: dp[v] += dp[u] * a dp[v] %= mod dp_sum[v] += (dp_sum[u] + dp[u] * l) * a dp_sum[v] %= mod print(dp_sum[-1])