結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー lloyzlloyz
提出日時 2022-09-28 00:34:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,104 ms / 2,000 ms
コード長 782 bytes
コンパイル時間 1,236 ms
コンパイル使用メモリ 86,328 KB
実行使用メモリ 162,072 KB
最終ジャッジ日時 2023-08-24 04:14:02
合計ジャッジ時間 28,943 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 90 ms
71,372 KB
testcase_01 AC 92 ms
71,856 KB
testcase_02 AC 525 ms
116,392 KB
testcase_03 AC 770 ms
157,956 KB
testcase_04 AC 858 ms
157,728 KB
testcase_05 AC 631 ms
152,032 KB
testcase_06 AC 644 ms
151,856 KB
testcase_07 AC 264 ms
99,588 KB
testcase_08 AC 580 ms
158,372 KB
testcase_09 AC 186 ms
82,396 KB
testcase_10 AC 337 ms
112,688 KB
testcase_11 AC 288 ms
103,632 KB
testcase_12 AC 209 ms
89,304 KB
testcase_13 AC 728 ms
127,716 KB
testcase_14 AC 761 ms
136,048 KB
testcase_15 AC 904 ms
149,580 KB
testcase_16 AC 482 ms
106,788 KB
testcase_17 AC 1,059 ms
153,312 KB
testcase_18 AC 435 ms
100,592 KB
testcase_19 AC 833 ms
148,764 KB
testcase_20 AC 385 ms
96,696 KB
testcase_21 AC 501 ms
104,100 KB
testcase_22 AC 868 ms
142,896 KB
testcase_23 AC 121 ms
77,968 KB
testcase_24 AC 127 ms
77,948 KB
testcase_25 AC 198 ms
86,244 KB
testcase_26 AC 496 ms
114,488 KB
testcase_27 AC 526 ms
113,724 KB
testcase_28 AC 732 ms
138,604 KB
testcase_29 AC 269 ms
86,572 KB
testcase_30 AC 761 ms
147,140 KB
testcase_31 AC 680 ms
127,628 KB
testcase_32 AC 410 ms
107,784 KB
testcase_33 AC 977 ms
148,644 KB
testcase_34 AC 452 ms
101,220 KB
testcase_35 AC 749 ms
146,748 KB
testcase_36 AC 127 ms
77,992 KB
testcase_37 AC 164 ms
79,664 KB
testcase_38 AC 134 ms
78,000 KB
testcase_39 AC 155 ms
79,512 KB
testcase_40 AC 111 ms
76,260 KB
testcase_41 AC 1,104 ms
162,072 KB
testcase_42 AC 439 ms
102,940 KB
testcase_43 AC 569 ms
119,460 KB
testcase_44 AC 296 ms
93,220 KB
testcase_45 AC 661 ms
118,252 KB
testcase_46 AC 89 ms
71,652 KB
testcase_47 AC 90 ms
71,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
from math import sqrt
from heapq import heapify, heappop, heappush

n, m = map(int, input().split())
x, y = map(int, input().split())
x -= 1
y -= 1
P = [list(map(int, input().split())) for _ in range(n)]
Edge = defaultdict(list)
for _ in range(m):
    p, q = map(int, input().split())
    p -= 1
    q -= 1
    d = sqrt((P[p][0] - P[q][0])**2 + (P[p][1] - P[q][1])**2)
    Edge[p].append((q, d))
    Edge[q].append((p, d))

INF = 10**18
D = [INF for _ in range(n)]
D[x] = 0
H = [(0, x)]
heapify(H)
while H:
    d, cp = heappop(H)
    if cp == y:
        print(d)
        break
    if d > D[cp]:
        continue
    for np, dd in Edge[cp]:
        if d + dd >= D[np]:
            continue
        D[np] = d + dd
        heappush(H, (d + dd, np))
0