結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー ThetaTheta
提出日時 2023-01-27 18:24:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,568 ms / 2,000 ms
コード長 1,281 bytes
コンパイル時間 686 ms
コンパイル使用メモリ 86,988 KB
実行使用メモリ 194,508 KB
最終ジャッジ日時 2023-09-10 12:23:18
合計ジャッジ時間 38,148 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
71,696 KB
testcase_01 AC 83 ms
71,576 KB
testcase_02 AC 735 ms
137,824 KB
testcase_03 AC 1,397 ms
193,900 KB
testcase_04 AC 1,380 ms
194,508 KB
testcase_05 AC 870 ms
191,368 KB
testcase_06 AC 913 ms
191,232 KB
testcase_07 AC 301 ms
104,696 KB
testcase_08 AC 619 ms
177,212 KB
testcase_09 AC 222 ms
87,012 KB
testcase_10 AC 389 ms
121,404 KB
testcase_11 AC 322 ms
109,284 KB
testcase_12 AC 537 ms
103,420 KB
testcase_13 AC 1,171 ms
153,052 KB
testcase_14 AC 1,190 ms
168,304 KB
testcase_15 AC 1,390 ms
180,924 KB
testcase_16 AC 902 ms
124,032 KB
testcase_17 AC 1,515 ms
186,944 KB
testcase_18 AC 649 ms
111,544 KB
testcase_19 AC 1,292 ms
182,784 KB
testcase_20 AC 442 ms
104,628 KB
testcase_21 AC 869 ms
122,804 KB
testcase_22 AC 1,331 ms
176,024 KB
testcase_23 AC 155 ms
80,272 KB
testcase_24 AC 160 ms
79,928 KB
testcase_25 AC 470 ms
100,920 KB
testcase_26 AC 900 ms
136,148 KB
testcase_27 AC 926 ms
133,236 KB
testcase_28 AC 1,498 ms
176,036 KB
testcase_29 AC 324 ms
90,784 KB
testcase_30 AC 1,568 ms
186,152 KB
testcase_31 AC 982 ms
154,576 KB
testcase_32 AC 749 ms
126,380 KB
testcase_33 AC 1,336 ms
180,416 KB
testcase_34 AC 706 ms
114,932 KB
testcase_35 AC 1,433 ms
186,060 KB
testcase_36 AC 152 ms
79,432 KB
testcase_37 AC 208 ms
81,248 KB
testcase_38 AC 157 ms
79,508 KB
testcase_39 AC 185 ms
80,228 KB
testcase_40 AC 126 ms
77,560 KB
testcase_41 AC 1,157 ms
187,168 KB
testcase_42 AC 459 ms
111,424 KB
testcase_43 AC 672 ms
133,580 KB
testcase_44 AC 338 ms
97,956 KB
testcase_45 AC 698 ms
131,380 KB
testcase_46 AC 80 ms
71,584 KB
testcase_47 AC 79 ms
71,276 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappop, heappush
from math import inf, sqrt
from operator import ne


class Point:
    def __init__(self, x, y) -> None:
        self.x = x
        self.y = y

    def distance_to(self, __o: object):
        if not isinstance(__o, Point):
            raise ValueError
        return sqrt((self.x - __o.x)**2 + (self.y - __o.y)**2)


def main():
    N, M = map(int, input().split())
    X, Y = map(int, input().split())
    X -= 1
    Y -= 1
    nodes = [Point(*map(int, input().split())) for _ in range(N)]
    weights = [{} for _ in range(N)]
    for _ in range(M):
        start, end = map(int, input().split())
        weights[start-1][end-1] = nodes[start-1].distance_to(nodes[end-1])
        weights[end-1][start-1] = weights[start-1][end-1]

    searched = []
    heappush(searched, (0, X))
    costs = [inf for _ in range(N)]
    decided = set()

    while searched:
        current_cost, next_node_idx = heappop(searched)
        if next_node_idx in decided:
            continue
        costs[next_node_idx] = current_cost
        decided.add(next_node_idx)
        for dest_idx, distance in weights[next_node_idx].items():
            heappush(searched, (current_cost + distance, dest_idx))

    print(costs[Y])


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