結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー titia
提出日時 2020-05-29 21:47:39
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,120 ms / 2,000 ms
コード長 612 bytes
コンパイル時間 329 ms
コンパイル使用メモリ 82,352 KB
実行使用メモリ 147,736 KB
最終ジャッジ日時 2024-11-06 03:35:46
合計ジャッジ時間 25,932 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 46
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M=map(int,input().split())
X,Y=map(int,input().split())
L=[tuple(map(int,input().split())) for i in range(N)]
E=[[] for i in range(N+1)]

from math import sqrt

for i in range(M):
    p,q=map(int,input().split())
    p-=1
    q-=1
    x0,y0=L[p]
    x1,y1=L[q]
    E[p].append((sqrt((x0-x1)**2+(y0-y1)**2),q))
    E[q].append((sqrt((x0-x1)**2+(y0-y1)**2),p))

import heapq
DP=[1<<62]*(N+1)
DP[X-1]=0

Q=[(0,X-1)]

while Q:
    now,x=heapq.heappop(Q)

    for le,to in E[x]:
        if DP[to]>DP[x]+le:
            DP[to]=DP[x]+le
            heapq.heappush(Q,(DP[to]+le,to))
print(DP[Y-1])
    
    
    
    
0