結果
| 問題 |
No.1065 電柱 / Pole (Easy)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-05-29 22:21:25 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,271 bytes |
| コンパイル時間 | 379 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 126,464 KB |
| 最終ジャッジ日時 | 2024-11-06 05:31:27 |
| 合計ジャッジ時間 | 27,839 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 33 TLE * 13 |
ソースコード
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
from math import sqrt
def dijkstra_heap(s):
import heapq
# 始点sから各頂点への最短距離
d = [float("inf")] * n
used = [True] * n # True:未確定
d[s] = 0
used[s] = False
edgelist = []
for e in graph[s]:
e.append(s)
heapq.heappush(edgelist, e)
while len(edgelist):
minedge = heapq.heappop(edgelist)
# まだ使われてない頂点の中から最小の距離のものを探す
if not used[minedge[1]]:
continue
v = minedge[1]
d[v] = minedge[0]
used[v] = False
for e in graph[v]:
if used[e[1]]:
heapq.heappush(edgelist, [e[0] + d[v], e[1]])
return d
n, m = map(int, readline().split())
x, y = map(int, readline().split())
pq = [list(map(int, readline().split())) for _ in range(n)]
graph = [[] for _ in range(n)]
for i in range(m):
p, q = map(int, readline().split())
p -= 1
q -= 1
v = sqrt((pq[p][0] - pq[q][0]) ** 2 + (pq[p][1] - pq[q][1]) ** 2)
graph[p].append([v, q])
graph[q].append([v, p])
print(dijkstra_heap(x - 1)[y - 1])