結果
問題 | No.1995 CHIKA Road |
ユーザー |
![]() |
提出日時 | 2022-12-14 12:18:44 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
MLE
|
実行時間 | - |
コード長 | 945 bytes |
コンパイル時間 | 847 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 526,932 KB |
最終ジャッジ日時 | 2024-11-08 03:43:48 |
合計ジャッジ時間 | 5,910 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 MLE * 1 |
other | -- * 37 |
ソースコード
from heapq import heapify, heappop, heappushfrom typing import Listdef dijkstra(edges: "List[List[(cost, to)]]", start_node: int) -> list:hq = []heapify(hq)dist = [float("inf")] * len(edges)heappush(hq, (0, start_node))dist[start_node] = 0while hq:min_cost, now = heappop(hq)if min_cost > dist[now]:continuefor cost, nxt in edges[now]:if dist[nxt] > dist[now] + cost:dist[nxt] = dist[now] + costheappush(hq, (dist[nxt], nxt))return distdef main():n, m = map(int, input().split())edge = [[] for _ in range(n + 1)]for _ in range(m):a, b = map(int, input().split())a -= 1b -= 1edge[a].append([2 * (b - a) - 1, b])for i in range(n - 1):edge[i].append([2, i + 1])ans = dijkstra(edge, 0)[n - 1]print(ans)if __name__ == "__main__":main()