結果
問題 |
No.1065 電柱 / Pole (Easy)
|
ユーザー |
|
提出日時 | 2023-09-07 10:44:54 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 923 ms / 2,000 ms |
コード長 | 934 bytes |
コンパイル時間 | 358 ms |
コンパイル使用メモリ | 82,268 KB |
実行使用メモリ | 161,864 KB |
最終ジャッジ日時 | 2024-06-25 04:57:57 |
合計ジャッジ時間 | 24,164 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 46 |
ソースコード
from heapq import heappop, heappush N, M = map(int, input().split()) X, Y = map(int, input().split()) pq = [list(map(int, input().split())) for _ in range(N)] PQ = [list(map(int, input().split())) for _ in range(M)] G = [[] for _ in range(N)] for i in range(M): a, b = PQ[i] a -= 1 b -= 1 d = ((pq[a][0]-pq[b][0])**2 + (pq[a][1]-pq[b][1])**2)**0.5 G[a].append((b, d)) G[b].append((a, d)) dist = [float('inf')] * N dist[X-1] = 0 # dijkstra def dijkstra(s, g): que = [] heappush(que, (0, s)) while que: cost, now = heappop(que) if dist[now] < cost: continue for nxt, d in G[now]: if nxt == now: continue nxt_cost = dist[now] + d if nxt_cost < dist[nxt]: dist[nxt] = nxt_cost heappush(que, (nxt_cost, nxt)) return dist[g] ans = dijkstra(X-1, Y-1) print(ans)