結果
問題 | No.1301 Strange Graph Shortest Path |
ユーザー | Shirotsume |
提出日時 | 2023-02-17 21:01:28 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,580 bytes |
コンパイル時間 | 202 ms |
コンパイル使用メモリ | 82,448 KB |
実行使用メモリ | 152,152 KB |
最終ジャッジ日時 | 2024-07-19 12:08:33 |
合計ジャッジ時間 | 26,405 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 44 ms
54,192 KB |
testcase_01 | AC | 44 ms
54,644 KB |
testcase_02 | WA | - |
testcase_03 | AC | 575 ms
134,560 KB |
testcase_04 | AC | 785 ms
149,840 KB |
testcase_05 | AC | 605 ms
148,504 KB |
testcase_06 | AC | 735 ms
147,640 KB |
testcase_07 | AC | 685 ms
143,244 KB |
testcase_08 | AC | 568 ms
133,420 KB |
testcase_09 | AC | 719 ms
139,176 KB |
testcase_10 | WA | - |
testcase_11 | AC | 755 ms
146,344 KB |
testcase_12 | AC | 768 ms
147,832 KB |
testcase_13 | AC | 692 ms
148,836 KB |
testcase_14 | AC | 689 ms
137,044 KB |
testcase_15 | AC | 680 ms
137,492 KB |
testcase_16 | AC | 794 ms
151,104 KB |
testcase_17 | AC | 715 ms
147,928 KB |
testcase_18 | AC | 635 ms
134,976 KB |
testcase_19 | AC | 739 ms
147,744 KB |
testcase_20 | AC | 717 ms
144,188 KB |
testcase_21 | AC | 769 ms
150,300 KB |
testcase_22 | AC | 742 ms
150,280 KB |
testcase_23 | AC | 714 ms
148,400 KB |
testcase_24 | AC | 718 ms
149,152 KB |
testcase_25 | AC | 808 ms
148,948 KB |
testcase_26 | AC | 726 ms
144,908 KB |
testcase_27 | AC | 753 ms
145,208 KB |
testcase_28 | AC | 601 ms
138,516 KB |
testcase_29 | WA | - |
testcase_30 | AC | 789 ms
148,816 KB |
testcase_31 | AC | 801 ms
149,856 KB |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | AC | 753 ms
152,008 KB |
ソースコード
import sys from collections import deque, Counter input = lambda: sys.stdin.readline().rstrip() ii = lambda: int(input()) mi = lambda: map(int, input().split()) li = lambda: list(mi()) inf = 2 ** 63 - 1 mod = 998244353 def Dijkstra(s, graph): INF = 2 ** 63 - 1 import heapq n = len(graph) dist = [INF] * n dist[s] = 0 bef = [0] * n bef[s] = s hq = [(0, s)] heapq.heapify(hq) while hq: c, now = heapq.heappop(hq) if c > dist[now]: continue for to, cost in graph[now]: if dist[now] + cost < dist[to]: dist[to] = cost + dist[now] bef[to] = now heapq.heappush(hq, (dist[to], + to)) return dist, bef def DijkstraRest(bef, t): now = t ret = [] while bef[now] != now: ret.append((bef[now], now)) now = bef[now] ret.reverse() return ret n, m = mi() edge = [li() for _ in range(m)] D = {} for u, v, c, d in edge: u -= 1; v -= 1 D[u, v] = D[v, u] = (c, d) graph = [[] for _ in range(n)] for V in D.keys(): u, v = V graph[u].append((v, D[V][0])) graph[v].append((u, D[V][0])) dist, r = Dijkstra(0, graph) ans = dist[n - 1] R = set(DijkstraRest(r, n - 1)) graph = [[] for _ in range(n)] for V in D.keys(): u, v = V if (u, v) in R or (v, u) in R: graph[u].append((v, D[V][1])) graph[v].append((u, D[V][1])) else: graph[u].append((v, D[V][0])) graph[v].append((u, D[V][0])) dist, r = Dijkstra(0, graph) ans += dist[n - 1] print(ans)