結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー RiburaRibura
提出日時 2020-05-29 22:21:25
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,271 bytes
コンパイル時間 92 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 126,464 KB
最終ジャッジ日時 2024-04-23 23:11:36
合計ジャッジ時間 27,024 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
18,076 KB
testcase_01 AC 32 ms
10,880 KB
testcase_02 AC 1,417 ms
68,096 KB
testcase_03 TLE -
testcase_04 TLE -
testcase_05 AC 1,699 ms
113,024 KB
testcase_06 AC 1,710 ms
112,896 KB
testcase_07 AC 371 ms
41,600 KB
testcase_08 AC 1,535 ms
126,464 KB
testcase_09 AC 127 ms
20,736 KB
testcase_10 AC 620 ms
62,464 KB
testcase_11 AC 417 ms
46,080 KB
testcase_12 AC 774 ms
42,752 KB
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 AC 1,521 ms
61,568 KB
testcase_17 TLE -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from math import sqrt


def dijkstra_heap(s):
    import heapq
    # 始点sから各頂点への最短距離
    d = [float("inf")] * n
    used = [True] * n  # True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for e in graph[s]:
        e.append(s)
        heapq.heappush(edgelist, e)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        # まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge[1]]:
            continue
        v = minedge[1]
        d[v] = minedge[0]
        used[v] = False
        for e in graph[v]:
            if used[e[1]]:
                heapq.heappush(edgelist, [e[0] + d[v], e[1]])
    return d


n, m = map(int, readline().split())
x, y = map(int, readline().split())
pq = [list(map(int, readline().split())) for _ in range(n)]
graph = [[] for _ in range(n)]
for i in range(m):
    p, q = map(int, readline().split())
    p -= 1
    q -= 1
    v = sqrt((pq[p][0] - pq[q][0]) ** 2 + (pq[p][1] - pq[q][1]) ** 2)
    graph[p].append([v, q])
    graph[q].append([v, p])
print(dijkstra_heap(x - 1)[y - 1])
0