結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー はむ吉🐹はむ吉🐹
提出日時 2020-05-29 22:13:10
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,331 bytes
コンパイル時間 329 ms
コンパイル使用メモリ 82,416 KB
実行使用メモリ 179,868 KB
最終ジャッジ日時 2024-04-23 22:54:44
合計ジャッジ時間 33,886 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
54,256 KB
testcase_01 AC 38 ms
54,192 KB
testcase_02 AC 832 ms
127,524 KB
testcase_03 AC 1,146 ms
177,632 KB
testcase_04 AC 1,108 ms
175,732 KB
testcase_05 AC 874 ms
176,100 KB
testcase_06 AC 900 ms
176,424 KB
testcase_07 AC 342 ms
103,100 KB
testcase_08 WA -
testcase_09 AC 201 ms
85,572 KB
testcase_10 AC 459 ms
118,868 KB
testcase_11 AC 409 ms
106,116 KB
testcase_12 AC 301 ms
95,168 KB
testcase_13 AC 984 ms
143,548 KB
testcase_14 AC 1,104 ms
155,176 KB
testcase_15 AC 1,319 ms
171,644 KB
testcase_16 AC 691 ms
117,252 KB
testcase_17 AC 1,357 ms
179,868 KB
testcase_18 AC 500 ms
104,204 KB
testcase_19 AC 1,260 ms
172,128 KB
testcase_20 AC 452 ms
101,748 KB
testcase_21 AC 602 ms
111,636 KB
testcase_22 AC 1,225 ms
163,668 KB
testcase_23 AC 83 ms
76,824 KB
testcase_24 AC 91 ms
77,220 KB
testcase_25 AC 232 ms
92,244 KB
testcase_26 AC 739 ms
124,292 KB
testcase_27 AC 754 ms
125,264 KB
testcase_28 AC 1,265 ms
161,972 KB
testcase_29 AC 265 ms
87,068 KB
testcase_30 AC 1,278 ms
170,164 KB
testcase_31 AC 886 ms
142,696 KB
testcase_32 AC 626 ms
117,728 KB
testcase_33 AC 1,282 ms
172,192 KB
testcase_34 AC 524 ms
106,892 KB
testcase_35 AC 1,281 ms
175,772 KB
testcase_36 AC 115 ms
77,188 KB
testcase_37 AC 156 ms
78,820 KB
testcase_38 AC 116 ms
78,600 KB
testcase_39 AC 154 ms
78,828 KB
testcase_40 AC 66 ms
70,664 KB
testcase_41 AC 1,584 ms
176,984 KB
testcase_42 AC 529 ms
107,704 KB
testcase_43 AC 862 ms
129,176 KB
testcase_44 AC 393 ms
96,156 KB
testcase_45 AC 824 ms
127,752 KB
testcase_46 AC 38 ms
53,704 KB
testcase_47 AC 38 ms
53,664 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