結果
| 問題 | No.1065 電柱 / Pole (Easy) | 
| コンテスト | |
| ユーザー |  Kiri8128 | 
| 提出日時 | 2020-05-30 00:16:49 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 1,097 ms / 2,000 ms | 
| コード長 | 913 bytes | 
| コンパイル時間 | 165 ms | 
| コンパイル使用メモリ | 82,380 KB | 
| 実行使用メモリ | 152,840 KB | 
| 最終ジャッジ日時 | 2024-11-06 09:38:38 | 
| 合計ジャッジ時間 | 25,091 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 46 | 
ソースコード
from heapq import heapify, heappush as hpush, heappop as hpop
from math import sqrt
import sys
input = lambda: sys.stdin.readline().rstrip()
N, M = map(int, input().split())
s, t = map(int, input().split())
s, t = s-1, t-1
L = []
for _ in range(N):
    a, b = map(int, input().split())
    L.append((a, b))
X = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    d = sqrt((L[a][0] - L[b][0]) ** 2 + (L[a][1] - L[b][1]) ** 2)
    X[a].append([b, d])
    X[b].append([a, d])
def dijkstra(n, E, i0=0):
    h = [[0, i0]]
    D = [-1] * n
    done = [0] * n
    D[i0] = 0
    
    while h:
        d, i = hpop(h)
        done[i] = 1
        for j, w in E[i]:
            nd = d + w
            if D[j] < 0 or D[j] > nd:
                if done[j] == 0:
                    hpush(h, [nd, j])
                    D[j] = nd
    return D
print(dijkstra(N, X, s)[t])
            
            
            
        