結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー 👑 Kazun
提出日時 2021-02-10 18:17:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 703 ms / 2,000 ms
コード長 991 bytes
コンパイル時間 180 ms
コンパイル使用メモリ 82,260 KB
実行使用メモリ 149,700 KB
最終ジャッジ日時 2024-07-08 04:58:56
合計ジャッジ時間 16,690 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 46
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import sqrt
def dist(p,q):
    return sqrt((p[0]-q[0])**2+(p[1]-q[1])**2)

class A:
    def __init__(self,d,x):
        self.d=d
        self.x=x

    def __le__(self,other):
        return self.d<=other.d

    def __lt__(self,other):
        return self.d<other.d

    def __iter__(self):
        yield from (self.d,self.x)
#================================================
import sys
from heapq import heappop,heappush
input=sys.stdin.readline

N,M=map(int,input().split())
X,Y=map(int,input().split())
Pos=[("*","*")]
for _ in range(N):
    x,y=map(int,input().split())
    Pos.append((x,y))

E=[set() for _ in range(N+1)]
for _ in range(M):
    p,q=map(int,input().split())
    E[p].add(q)
    E[q].add(p)

inf=float("inf")
T=[inf]*(N+1)
T[X]=0
Q=[A(0,X)]
while Q:
    c,p=heappop(Q)
    if T[p]<c:
        continue

    for q in E[p]:
        if T[q]>c+dist(Pos[p],Pos[q]):
            T[q]=c+dist(Pos[p],Pos[q])
            heappush(Q,A(c+dist(Pos[p],Pos[q]),q))

print(T[Y])
0