結果
問題 | No.1364 [Renaming] Road to Cherry from Zelkova |
ユーザー | rlangevin |
提出日時 | 2024-01-08 01:37:59 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 505 ms / 2,500 ms |
コード長 | 1,589 bytes |
コンパイル時間 | 402 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 149,984 KB |
最終ジャッジ日時 | 2024-09-27 19:35:07 |
合計ジャッジ時間 | 15,278 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
54,016 KB |
testcase_01 | AC | 47 ms
53,632 KB |
testcase_02 | AC | 42 ms
53,632 KB |
testcase_03 | AC | 41 ms
54,272 KB |
testcase_04 | AC | 43 ms
54,528 KB |
testcase_05 | AC | 47 ms
54,144 KB |
testcase_06 | AC | 43 ms
54,016 KB |
testcase_07 | AC | 44 ms
54,784 KB |
testcase_08 | AC | 91 ms
78,848 KB |
testcase_09 | AC | 87 ms
77,952 KB |
testcase_10 | AC | 103 ms
78,848 KB |
testcase_11 | AC | 92 ms
78,848 KB |
testcase_12 | AC | 119 ms
80,144 KB |
testcase_13 | AC | 333 ms
120,004 KB |
testcase_14 | AC | 447 ms
126,160 KB |
testcase_15 | AC | 415 ms
127,120 KB |
testcase_16 | AC | 319 ms
110,616 KB |
testcase_17 | AC | 210 ms
104,716 KB |
testcase_18 | AC | 476 ms
140,912 KB |
testcase_19 | AC | 477 ms
141,004 KB |
testcase_20 | AC | 477 ms
141,352 KB |
testcase_21 | AC | 479 ms
141,624 KB |
testcase_22 | AC | 492 ms
140,952 KB |
testcase_23 | AC | 174 ms
93,348 KB |
testcase_24 | AC | 139 ms
94,208 KB |
testcase_25 | AC | 349 ms
114,176 KB |
testcase_26 | AC | 464 ms
122,984 KB |
testcase_27 | AC | 329 ms
107,412 KB |
testcase_28 | AC | 273 ms
106,368 KB |
testcase_29 | AC | 312 ms
115,044 KB |
testcase_30 | AC | 271 ms
103,188 KB |
testcase_31 | AC | 217 ms
97,792 KB |
testcase_32 | AC | 251 ms
103,032 KB |
testcase_33 | AC | 473 ms
126,900 KB |
testcase_34 | AC | 505 ms
132,048 KB |
testcase_35 | AC | 397 ms
129,536 KB |
testcase_36 | AC | 355 ms
125,952 KB |
testcase_37 | AC | 244 ms
120,040 KB |
testcase_38 | AC | 349 ms
149,744 KB |
testcase_39 | AC | 355 ms
149,344 KB |
testcase_40 | AC | 348 ms
149,472 KB |
testcase_41 | AC | 352 ms
149,736 KB |
testcase_42 | AC | 353 ms
149,984 KB |
testcase_43 | AC | 232 ms
124,032 KB |
testcase_44 | AC | 200 ms
118,932 KB |
testcase_45 | AC | 228 ms
118,276 KB |
testcase_46 | AC | 72 ms
87,996 KB |
testcase_47 | AC | 42 ms
54,596 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)] G1 = [[] for i in range(N + 1)] G2 = [[] 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]) G1[u].append(v) G2[v].append(u) dist1 = bfs(G1, 0) dist2 = bfs(G2, N) for u, v, l, a in D: if dist1[u] == -1 or dist1[v] == -1 or dist2[u] == -1 or dist2[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])