結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー rin204
提出日時 2022-04-17 17:24:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,228 ms / 2,000 ms
コード長 740 bytes
コンパイル時間 623 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 124,552 KB
最終ジャッジ日時 2024-12-26 11:07:02
合計ジャッジ時間 32,911 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 46
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import *

n, m = map(int, input().split())
x, y = map(int, input().split())
x -= 1
y -= 1
point = [list(map(int, input().split())) for _ in range(n)]
edges = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    edges[a].append(b)
    edges[b].append(a)

def f(i, j):
    dx = point[j][0] - point[i][0]
    dy = point[j][1] - point[i][1]
    return (dx * dx + dy * dy) ** 0.5

inf = 1e20
dist = [inf] * n
dist[x] = 0.0
hq = [(0.0, x)]
while hq:
    d, pos = heappop(hq)
    if dist[pos] < d:
        continue
    for npos in edges[pos]:
        c = f(pos, npos)
        if dist[npos] > d + c:
            dist[npos] = d + c
            heappush(hq, (d + c, npos))
print(dist[y])
0