結果
問題 | No.1364 [Renaming] Road to Cherry from Zelkova |
ユーザー | roaris |
提出日時 | 2021-01-23 20:44:19 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,695 bytes |
コンパイル時間 | 188 ms |
コンパイル使用メモリ | 82,224 KB |
実行使用メモリ | 489,824 KB |
最終ジャッジ日時 | 2024-06-10 05:30:05 |
合計ジャッジ時間 | 15,780 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 38 ms
59,776 KB |
testcase_01 | AC | 40 ms
54,144 KB |
testcase_02 | AC | 38 ms
54,016 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 | 135 ms
91,180 KB |
testcase_24 | AC | 97 ms
85,884 KB |
testcase_25 | AC | 236 ms
103,424 KB |
testcase_26 | AC | 337 ms
115,556 KB |
testcase_27 | AC | 218 ms
104,960 KB |
testcase_28 | AC | 190 ms
96,832 KB |
testcase_29 | AC | 214 ms
105,728 KB |
testcase_30 | AC | 188 ms
97,132 KB |
testcase_31 | AC | 160 ms
95,360 KB |
testcase_32 | AC | 190 ms
100,352 KB |
testcase_33 | AC | 308 ms
112,852 KB |
testcase_34 | AC | 328 ms
113,600 KB |
testcase_35 | AC | 315 ms
121,824 KB |
testcase_36 | AC | 289 ms
118,912 KB |
testcase_37 | AC | 161 ms
97,460 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 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])