結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー tobusakana
提出日時 2022-12-10 20:11:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 989 ms / 2,000 ms
コード長 681 bytes
コンパイル時間 580 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 162,816 KB
最終ジャッジ日時 2024-10-14 23:54:01
合計ジャッジ時間 25,418 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 46
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M = map(int,input().split())
X,Y = map(int,input().split())
PQ = [list(map(int,input().split())) for i in range(N)]

import heapq as hq
q = []
hq.heappush(q, (0, X - 1))
G = [[] for i in range(N)]
for _ in range(M):
    i,j = map(lambda x:int(x) - 1,input().split())
    d = ((PQ[i][0] - PQ[j][0]) ** 2 + (PQ[i][1] - PQ[j][1]) ** 2) ** 0.5
    G[i].append([j, d])
    G[j].append([i, d])
    
visited = [False] * N
while q:
    dist, v = hq.heappop(q)
    if visited[v]:
        continue
    visited[v] = True
    if v == Y - 1:
        print(dist)
        break
    for child, d in G[v]:
        if visited[child]:
            continue
        hq.heappush(q, (dist + d, child))
0