結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー nehan_der_thal
提出日時 2020-05-29 22:50:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 815 ms / 2,000 ms
コード長 803 bytes
コンパイル時間 293 ms
コンパイル使用メモリ 82,344 KB
実行使用メモリ 136,864 KB
最終ジャッジ日時 2024-11-06 06:59:18
合計ジャッジ時間 19,084 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 46
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys;input=sys.stdin.readline
from heapq import *
def dijkstra_heapq(s, cost):
    d = [float("inf")] * N
    h = [(0, s)]
    d[s] = 0
    while h:
        vc, v = heappop(h)
#        print(h)
        if vc > d[v]:
            continue
        for j, c in cost[v]:
            if vc+c<d[j]:
                d[j] = vc+c
                heappush(h, (vc+c, j))
    return d

N, M = map(int,input().split())
X, Y = map(int,input().split())
V = []
for _ in range(N):
    p, q = map(int, input().split())
    V.append((p, q))

cost = [[] for _ in range(N)]
for _ in range(M):
    A, B = map(int, input().split())
    a, b = V[A-1]
    c, d = V[B-1]
    cost[A-1].append((B-1, ((a-c)**2+(b-d)**2)**0.5))
    cost[B-1].append((A-1, ((a-c)**2+(b-d)**2)**0.5))

d = dijkstra_heapq(X-1,cost)
print(d[Y-1])

0