結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー はむ吉🐹はむ吉🐹
提出日時 2020-05-29 22:11:13
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,334 bytes
コンパイル時間 90 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 137,472 KB
最終ジャッジ日時 2024-04-23 22:47:54
合計ジャッジ時間 6,079 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
16,640 KB
testcase_01 AC 34 ms
11,008 KB
testcase_02 AC 1,657 ms
84,096 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
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 #

#!/usr/bin/env python3

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("{:.12f}".format(res))


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