結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー はむ吉🐹はむ吉🐹
提出日時 2020-05-29 22:13:10
言語 PyPy3
(7.3.13)
結果
WA  
実行時間 -
コード長 1,331 bytes
コンパイル時間 358 ms
コンパイル使用メモリ 87,208 KB
実行使用メモリ 182,560 KB
最終ジャッジ日時 2023-08-06 02:21:22
合計ジャッジ時間 36,820 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,532 KB
testcase_01 AC 74 ms
71,440 KB
testcase_02 AC 948 ms
129,976 KB
testcase_03 AC 1,238 ms
180,412 KB
testcase_04 AC 1,209 ms
178,392 KB
testcase_05 AC 908 ms
176,260 KB
testcase_06 AC 918 ms
175,876 KB
testcase_07 AC 379 ms
105,124 KB
testcase_08 WA -
testcase_09 AC 247 ms
87,968 KB
testcase_10 AC 529 ms
121,000 KB
testcase_11 AC 406 ms
107,804 KB
testcase_12 AC 274 ms
96,116 KB
testcase_13 AC 1,094 ms
145,936 KB
testcase_14 AC 1,187 ms
156,468 KB
testcase_15 AC 1,404 ms
174,980 KB
testcase_16 AC 807 ms
119,708 KB
testcase_17 AC 1,498 ms
182,560 KB
testcase_18 AC 596 ms
105,820 KB
testcase_19 AC 1,368 ms
173,996 KB
testcase_20 AC 507 ms
103,740 KB
testcase_21 AC 677 ms
114,196 KB
testcase_22 AC 1,285 ms
166,380 KB
testcase_23 AC 120 ms
78,836 KB
testcase_24 AC 128 ms
78,704 KB
testcase_25 AC 256 ms
92,792 KB
testcase_26 AC 816 ms
127,196 KB
testcase_27 AC 837 ms
127,452 KB
testcase_28 AC 1,311 ms
164,760 KB
testcase_29 AC 310 ms
89,400 KB
testcase_30 AC 1,349 ms
172,096 KB
testcase_31 AC 973 ms
146,708 KB
testcase_32 AC 713 ms
120,896 KB
testcase_33 AC 1,376 ms
174,104 KB
testcase_34 AC 606 ms
110,300 KB
testcase_35 AC 1,351 ms
178,132 KB
testcase_36 AC 144 ms
79,292 KB
testcase_37 AC 203 ms
81,388 KB
testcase_38 AC 162 ms
79,264 KB
testcase_39 AC 204 ms
81,120 KB
testcase_40 AC 105 ms
78,008 KB
testcase_41 AC 1,644 ms
179,208 KB
testcase_42 AC 603 ms
109,232 KB
testcase_43 AC 913 ms
131,540 KB
testcase_44 AC 454 ms
98,936 KB
testcase_45 AC 895 ms
130,348 KB
testcase_46 AC 76 ms
71,368 KB
testcase_47 AC 73 ms
71,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env pypy3

import heapq
import math
 
 
INF = 10 ** 8


def dijkstra(num_vertices, adj_list, source=0):
    dist = [INF for _ in range(num_vertices)]
    dist[source] = 0
    pq = [(dist[u], u) for u in range(num_vertices)]
    heapq.heapify(pq)
    while pq:
        _, u = heapq.heappop(pq)
        for v, cost in adj_list[u]:
            new_length = dist[u] + cost
            if new_length < dist[v]:
                dist[v] = new_length
                heapq.heappush(pq, (new_length, v))
    return dist



def minimize(n, adj_list, pole_start, pole_end):
    dist = dijkstra(n, adj_list, pole_start)
    res = dist[pole_end]
    return res


def main():
    n, m = (int(z) for z in input().split())
    pole_start, pole_end = (int(z) - 1 for z in input().split())
    pole_poss = []
    for _ in range(n):
        x0, y0 = (float(z) for z in input().split())
        pole_poss.append((x0, y0))
    adj_list = [set() for _ in range(n)]
    for _ in range(m):
        st, en = (int(z) - 1 for z in input().split())
        dist = math.hypot(pole_poss[st][0] - pole_poss[en][0], pole_poss[st][1] - pole_poss[en][1])
        adj_list[st].add((en, dist))
        adj_list[en].add((st, dist))
    res = minimize(n, adj_list, pole_start, pole_end)
    print("{:.8f}".format(res))


if __name__ == '__main__':
    main()
0