結果

問題 No.1065 電柱 / Pole (Easy)
コンテスト
ユーザー tktk_snsn
提出日時 2020-05-29 22:03:52
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 1,288 ms / 2,000 ms
コード長 767 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 973 ms
コンパイル使用メモリ 20,700 KB
実行使用メモリ 109,796 KB
最終ジャッジ日時 2026-05-06 06:48:31
合計ジャッジ時間 30,995 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 46
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import heapq
import math
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

N, M = map(int, input().split())
S, T = map(int, input().split())
xy = tuple(tuple(map(int, input().split())) for _ in range(N))
edge = [[] for _ in range(N + 1)]
for _ in range(M):
    p, q = map(int, input().split())
    x1, y1 = xy[p - 1]
    x2, y2 = xy[q - 1]
    d = math.hypot(x1 - x2, y1 - y2)
    edge[p].append((q, d))
    edge[q].append((p, d))

inf = 10**18
dist = [inf] * (N + 1)
dist[S] = 0
que = [(0, S)]
while que:
    c, s = heapq.heappop(que)
    if dist[s] < c:
        continue
    cost = dist[s]
    for t, d in edge[s]:
        if dist[t] > cost + d:
            dist[t] = cost + d
            heapq.heappush(que, (cost+d, t))

print(dist[T])
0