結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー 👑 Kazun
提出日時 2021-02-10 18:14:05
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 627 ms / 2,000 ms
コード長 738 bytes
コンパイル時間 405 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 145,628 KB
最終ジャッジ日時 2024-07-08 04:55:46
合計ジャッジ時間 17,007 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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)
#================================================
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=[(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,(c+dist(Pos[p],Pos[q]),q))

print(T[Y])
0