結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー 👑 rin204rin204
提出日時 2022-04-17 17:24:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 995 ms / 2,000 ms
コード長 740 bytes
コンパイル時間 475 ms
コンパイル使用メモリ 87,156 KB
実行使用メモリ 126,280 KB
最終ジャッジ日時 2023-08-27 03:44:05
合計ジャッジ時間 28,655 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 89 ms
72,080 KB
testcase_01 AC 77 ms
71,548 KB
testcase_02 AC 593 ms
103,272 KB
testcase_03 AC 762 ms
126,280 KB
testcase_04 AC 748 ms
125,792 KB
testcase_05 AC 515 ms
124,972 KB
testcase_06 AC 515 ms
125,640 KB
testcase_07 AC 228 ms
90,792 KB
testcase_08 AC 478 ms
123,156 KB
testcase_09 AC 172 ms
83,176 KB
testcase_10 AC 286 ms
98,464 KB
testcase_11 AC 239 ms
90,636 KB
testcase_12 AC 193 ms
80,620 KB
testcase_13 AC 690 ms
106,940 KB
testcase_14 AC 785 ms
113,852 KB
testcase_15 AC 900 ms
120,436 KB
testcase_16 AC 497 ms
94,728 KB
testcase_17 AC 977 ms
123,536 KB
testcase_18 AC 397 ms
88,704 KB
testcase_19 AC 896 ms
124,116 KB
testcase_20 AC 349 ms
89,972 KB
testcase_21 AC 445 ms
91,012 KB
testcase_22 AC 849 ms
117,996 KB
testcase_23 AC 107 ms
78,100 KB
testcase_24 AC 114 ms
78,272 KB
testcase_25 AC 182 ms
80,284 KB
testcase_26 AC 525 ms
101,260 KB
testcase_27 AC 559 ms
99,380 KB
testcase_28 AC 826 ms
113,860 KB
testcase_29 AC 234 ms
81,316 KB
testcase_30 AC 877 ms
120,504 KB
testcase_31 AC 637 ms
108,944 KB
testcase_32 AC 492 ms
99,108 KB
testcase_33 AC 995 ms
123,828 KB
testcase_34 AC 414 ms
90,660 KB
testcase_35 AC 856 ms
121,408 KB
testcase_36 AC 119 ms
78,512 KB
testcase_37 AC 175 ms
79,268 KB
testcase_38 AC 130 ms
79,412 KB
testcase_39 AC 169 ms
79,388 KB
testcase_40 AC 99 ms
76,828 KB
testcase_41 AC 984 ms
123,988 KB
testcase_42 AC 409 ms
93,456 KB
testcase_43 AC 579 ms
102,488 KB
testcase_44 AC 303 ms
87,928 KB
testcase_45 AC 570 ms
102,364 KB
testcase_46 AC 76 ms
71,512 KB
testcase_47 AC 77 ms
71,560 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import *

n, m = map(int, input().split())
x, y = map(int, input().split())
x -= 1
y -= 1
point = [list(map(int, input().split())) for _ in range(n)]
edges = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    edges[a].append(b)
    edges[b].append(a)

def f(i, j):
    dx = point[j][0] - point[i][0]
    dy = point[j][1] - point[i][1]
    return (dx * dx + dy * dy) ** 0.5

inf = 1e20
dist = [inf] * n
dist[x] = 0.0
hq = [(0.0, x)]
while hq:
    d, pos = heappop(hq)
    if dist[pos] < d:
        continue
    for npos in edges[pos]:
        c = f(pos, npos)
        if dist[npos] > d + c:
            dist[npos] = d + c
            heappush(hq, (d + c, npos))
print(dist[y])
0