結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー RiburaRibura
提出日時 2020-05-29 22:21:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,617 ms / 2,000 ms
コード長 1,271 bytes
コンパイル時間 177 ms
コンパイル使用メモリ 82,592 KB
実行使用メモリ 166,636 KB
最終ジャッジ日時 2024-04-23 23:13:43
合計ジャッジ時間 34,371 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
53,924 KB
testcase_01 AC 41 ms
54,656 KB
testcase_02 AC 627 ms
119,272 KB
testcase_03 AC 1,358 ms
164,832 KB
testcase_04 AC 1,308 ms
165,344 KB
testcase_05 AC 851 ms
166,636 KB
testcase_06 AC 852 ms
166,420 KB
testcase_07 AC 126 ms
91,228 KB
testcase_08 AC 318 ms
154,228 KB
testcase_09 AC 86 ms
79,144 KB
testcase_10 AC 180 ms
111,088 KB
testcase_11 AC 143 ms
100,148 KB
testcase_12 AC 533 ms
105,136 KB
testcase_13 AC 1,172 ms
139,596 KB
testcase_14 AC 1,228 ms
144,968 KB
testcase_15 AC 1,476 ms
156,460 KB
testcase_16 AC 889 ms
120,264 KB
testcase_17 AC 1,605 ms
161,988 KB
testcase_18 AC 694 ms
109,520 KB
testcase_19 AC 1,299 ms
155,020 KB
testcase_20 AC 400 ms
99,220 KB
testcase_21 AC 911 ms
121,020 KB
testcase_22 AC 1,351 ms
150,764 KB
testcase_23 AC 99 ms
78,448 KB
testcase_24 AC 106 ms
78,560 KB
testcase_25 AC 452 ms
102,560 KB
testcase_26 AC 757 ms
121,716 KB
testcase_27 AC 903 ms
124,212 KB
testcase_28 AC 1,617 ms
157,812 KB
testcase_29 AC 272 ms
89,616 KB
testcase_30 AC 1,458 ms
157,352 KB
testcase_31 AC 923 ms
132,540 KB
testcase_32 AC 618 ms
113,172 KB
testcase_33 AC 1,449 ms
153,496 KB
testcase_34 AC 672 ms
110,556 KB
testcase_35 AC 1,493 ms
159,848 KB
testcase_36 AC 99 ms
77,784 KB
testcase_37 AC 118 ms
78,096 KB
testcase_38 AC 101 ms
77,696 KB
testcase_39 AC 116 ms
78,748 KB
testcase_40 AC 63 ms
66,304 KB
testcase_41 AC 1,044 ms
155,156 KB
testcase_42 AC 362 ms
101,644 KB
testcase_43 AC 581 ms
118,588 KB
testcase_44 AC 262 ms
93,056 KB
testcase_45 AC 570 ms
117,248 KB
testcase_46 AC 42 ms
54,260 KB
testcase_47 AC 40 ms
53,568 KB
権限があれば一括ダウンロードができます

ソースコード

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