結果
問題 | No.1301 Strange Graph Shortest Path |
ユーザー | eijirou |
提出日時 | 2020-11-27 22:57:17 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,729 bytes |
コンパイル時間 | 245 ms |
コンパイル使用メモリ | 82,368 KB |
実行使用メモリ | 111,772 KB |
最終ジャッジ日時 | 2024-07-26 20:12:25 |
合計ジャッジ時間 | 20,259 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 39 ms
53,120 KB |
testcase_01 | AC | 38 ms
53,680 KB |
testcase_02 | WA | - |
testcase_03 | AC | 487 ms
100,368 KB |
testcase_04 | AC | 654 ms
109,968 KB |
testcase_05 | AC | 485 ms
102,692 KB |
testcase_06 | AC | 639 ms
107,488 KB |
testcase_07 | AC | 615 ms
105,468 KB |
testcase_08 | AC | 500 ms
100,896 KB |
testcase_09 | AC | 518 ms
105,384 KB |
testcase_10 | WA | - |
testcase_11 | AC | 560 ms
106,340 KB |
testcase_12 | AC | 530 ms
107,196 KB |
testcase_13 | AC | 504 ms
105,240 KB |
testcase_14 | AC | 650 ms
105,276 KB |
testcase_15 | AC | 475 ms
102,728 KB |
testcase_16 | AC | 642 ms
110,116 KB |
testcase_17 | AC | 573 ms
105,996 KB |
testcase_18 | AC | 591 ms
104,116 KB |
testcase_19 | AC | 490 ms
105,588 KB |
testcase_20 | AC | 580 ms
107,536 KB |
testcase_21 | AC | 554 ms
106,440 KB |
testcase_22 | AC | 636 ms
108,512 KB |
testcase_23 | AC | 489 ms
104,536 KB |
testcase_24 | AC | 640 ms
107,872 KB |
testcase_25 | AC | 615 ms
108,916 KB |
testcase_26 | AC | 579 ms
105,172 KB |
testcase_27 | AC | 491 ms
105,248 KB |
testcase_28 | AC | 470 ms
102,252 KB |
testcase_29 | WA | - |
testcase_30 | AC | 563 ms
107,756 KB |
testcase_31 | AC | 589 ms
108,704 KB |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | AC | 659 ms
107,532 KB |
ソースコード
from heapq import heappush, heappop from sys import stdin input = stdin.readline inf = 1 << 60 def main(): n, m = map(int, input().split()) edges = [[] for _ in range(n)] for _ in range(m): u, v, c, d = map(int, input().split()) edges[u-1].append([v-1, c, d]) edges[v-1].append([u-1, c, d]) for i in range(n): edges[i].sort(key=lambda x: x[0]) # dijkstra dist = [inf] * n dist[0] = 0 prev = [-1] * n heap = [] heappush(heap, (0, 0)) while heap: cost, u = heappop(heap) if u == n-1: break if dist[u] < cost: continue for v, c, d in edges[u]: if cost + c < dist[v]: dist[v] = cost + c prev[v] = u heappush(heap, (cost+c, v)) dist1 = dist[n-1] def binary_search(u, v): left = 0 right = len(edges[u]) - 1 while left < right: center = (left + right) // 2 if edges[u][center][0] < v: left = center + 1 else: right = center edges[u][left][1], edges[u][left][2] = edges[u][left][2], edges[u][left][1] u = n-1 while u > 0: v = prev[u] binary_search(u, v) binary_search(v, u) u = v # dijkstra dist = [inf] * n dist[0] = 0 heap = [] heappush(heap, (0, 0)) while heap: cost, u = heappop(heap) if u == n-1: break if dist[u] < cost: continue for v, c, d in edges[u]: if cost + c < dist[v]: dist[v] = cost + c heappush(heap, (cost+c, v)) print(dist1 + dist[n-1]) main()