結果
問題 | No.1364 [Renaming] Road to Cherry from Zelkova |
ユーザー | roaris |
提出日時 | 2021-01-23 20:44:19 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,695 bytes |
コンパイル時間 | 577 ms |
コンパイル使用メモリ | 82,156 KB |
実行使用メモリ | 474,336 KB |
最終ジャッジ日時 | 2024-12-31 14:07:15 |
合計ジャッジ時間 | 35,055 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 45 ms
62,264 KB |
testcase_01 | AC | 44 ms
452,996 KB |
testcase_02 | AC | 45 ms
61,880 KB |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | AC | 163 ms
91,112 KB |
testcase_24 | AC | 116 ms
85,856 KB |
testcase_25 | AC | 363 ms
103,396 KB |
testcase_26 | AC | 455 ms
115,116 KB |
testcase_27 | AC | 283 ms
104,944 KB |
testcase_28 | AC | 245 ms
97,168 KB |
testcase_29 | AC | 263 ms
105,464 KB |
testcase_30 | AC | 239 ms
97,360 KB |
testcase_31 | AC | 186 ms
94,928 KB |
testcase_32 | AC | 213 ms
100,136 KB |
testcase_33 | AC | 411 ms
112,376 KB |
testcase_34 | AC | 417 ms
113,824 KB |
testcase_35 | AC | 403 ms
122,076 KB |
testcase_36 | AC | 344 ms
118,956 KB |
testcase_37 | AC | 174 ms
97,584 KB |
testcase_38 | TLE | - |
testcase_39 | TLE | - |
testcase_40 | TLE | - |
testcase_41 | TLE | - |
testcase_42 | TLE | - |
testcase_43 | AC | 418 ms
223,696 KB |
testcase_44 | AC | 258 ms
110,672 KB |
testcase_45 | AC | 381 ms
196,176 KB |
testcase_46 | AC | 57 ms
74,308 KB |
testcase_47 | WA | - |
ソースコード
import sys input = sys.stdin.readline sys.setrecursionlimit(10**5+100) from collections import * def bfs(): dist = [-1]*(N+1) dist[0] = 0 q = deque([0]) while q: v = q.popleft() for nv in g[v]: if dist[nv]==-1: dist[nv] = dist[v]+1 q.append(nv) return dist def rbfs(): dist = [-1]*(N+1) dist[N] = 0 q = deque([N]) while q: v = q.popleft() for nv in rg[v]: if dist[nv]==-1: dist[nv] = dist[v]+1 q.append(nv) return dist def dfs(v, pv): global cycle seen[v] = True for nv in g[v]: if finished[nv]: continue if seen[nv] and not finished[nv]: cycle = True return dfs(nv, v); if cycle: return finished[v] = True N, M = map(int, input().split()) G = [[] for _ in range(N+1)] g = [[] for _ in range(N+1)] rg = [[] for _ in range(N+1)] for _ in range(M): u, v, l, a = map(int, input().split()) G[u].append((v, l, a)) g[u].append(v) rg[v].append(u) dist1, dist2 = bfs(), rbfs() seen = [False]*(N+1) finished = [False]*(N+1) cycle = False dfs(0, -1) if cycle: print('INF') exit() dpl = [0]*(N+1) dpc = [0]*(N+1) dpc[0] = 1 MOD = 10**9+7 q = deque([0]) while q: nq = deque([]) while q: v = q.popleft() for nv, l, a in G[v]: dpl[nv] += dpl[v]+dpc[v]*a*l dpl[nv] %= MOD dpc[nv] += dpc[v]*a dpc[nv] %= MOD nq.append(nv) q = nq print(dpl[N])