結果
問題 | No.1364 [Renaming] Road to Cherry from Zelkova |
ユーザー | roaris |
提出日時 | 2021-01-23 20:53:34 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,770 bytes |
コンパイル時間 | 354 ms |
コンパイル使用メモリ | 82,164 KB |
実行使用メモリ | 511,472 KB |
最終ジャッジ日時 | 2024-12-31 14:31:13 |
合計ジャッジ時間 | 37,524 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 45 ms
59,648 KB |
testcase_01 | AC | 45 ms
444,800 KB |
testcase_02 | AC | 44 ms
61,088 KB |
testcase_03 | AC | 45 ms
452,728 KB |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | AC | 89 ms
87,188 KB |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | AC | 87 ms
79,744 KB |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | AC | 185 ms
103,552 KB |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | AC | 160 ms
91,168 KB |
testcase_24 | AC | 112 ms
86,028 KB |
testcase_25 | AC | 309 ms
103,328 KB |
testcase_26 | AC | 435 ms
115,456 KB |
testcase_27 | AC | 282 ms
105,088 KB |
testcase_28 | AC | 241 ms
96,896 KB |
testcase_29 | AC | 256 ms
105,304 KB |
testcase_30 | AC | 245 ms
96,988 KB |
testcase_31 | AC | 190 ms
95,232 KB |
testcase_32 | AC | 211 ms
100,096 KB |
testcase_33 | AC | 406 ms
112,768 KB |
testcase_34 | AC | 431 ms
113,576 KB |
testcase_35 | AC | 411 ms
121,728 KB |
testcase_36 | AC | 373 ms
118,900 KB |
testcase_37 | AC | 183 ms
97,524 KB |
testcase_38 | TLE | - |
testcase_39 | TLE | - |
testcase_40 | TLE | - |
testcase_41 | TLE | - |
testcase_42 | TLE | - |
testcase_43 | AC | 443 ms
229,224 KB |
testcase_44 | AC | 264 ms
111,480 KB |
testcase_45 | AC | 414 ms
195,576 KB |
testcase_46 | AC | 61 ms
74,292 KB |
testcase_47 | TLE | - |
ソースコード
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 dist1[nv]==-1 or dist2[nv]==-1: continue 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] += a*dpl[v]+a*dpc[v]*l dpl[nv] %= MOD dpc[nv] += dpc[v]*a dpc[nv] %= MOD nq.append(nv) q = nq print(dpl[N])