結果
問題 | No.1364 [Renaming] Road to Cherry from Zelkova |
ユーザー | roaris |
提出日時 | 2021-01-23 20:53:34 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,770 bytes |
コンパイル時間 | 263 ms |
コンパイル使用メモリ | 82,248 KB |
実行使用メモリ | 440,868 KB |
最終ジャッジ日時 | 2024-06-10 05:44:04 |
合計ジャッジ時間 | 17,205 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 40 ms
59,776 KB |
testcase_01 | AC | 40 ms
54,272 KB |
testcase_02 | AC | 39 ms
54,400 KB |
testcase_03 | AC | 40 ms
54,016 KB |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | AC | 83 ms
80,072 KB |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | AC | 79 ms
79,232 KB |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | AC | 176 ms
103,040 KB |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | AC | 148 ms
90,804 KB |
testcase_24 | AC | 105 ms
85,704 KB |
testcase_25 | AC | 288 ms
103,296 KB |
testcase_26 | AC | 417 ms
115,200 KB |
testcase_27 | AC | 265 ms
104,960 KB |
testcase_28 | AC | 223 ms
96,412 KB |
testcase_29 | AC | 243 ms
105,088 KB |
testcase_30 | AC | 229 ms
97,336 KB |
testcase_31 | AC | 182 ms
94,924 KB |
testcase_32 | AC | 203 ms
100,352 KB |
testcase_33 | AC | 380 ms
112,336 KB |
testcase_34 | AC | 403 ms
113,536 KB |
testcase_35 | AC | 400 ms
121,676 KB |
testcase_36 | AC | 357 ms
118,400 KB |
testcase_37 | AC | 171 ms
97,424 KB |
testcase_38 | TLE | - |
testcase_39 | -- | - |
testcase_40 | -- | - |
testcase_41 | -- | - |
testcase_42 | -- | - |
testcase_43 | -- | - |
testcase_44 | -- | - |
testcase_45 | -- | - |
testcase_46 | -- | - |
testcase_47 | -- | - |
ソースコード
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])