結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー AEnAEn
提出日時 2022-05-21 16:15:12
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 951 ms / 2,000 ms
コード長 833 bytes
コンパイル時間 216 ms
コンパイル使用メモリ 81,556 KB
実行使用メモリ 145,624 KB
最終ジャッジ日時 2023-10-20 16:20:16
合計ジャッジ時間 26,264 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
53,436 KB
testcase_01 AC 36 ms
53,436 KB
testcase_02 AC 515 ms
111,220 KB
testcase_03 AC 720 ms
144,140 KB
testcase_04 AC 698 ms
144,256 KB
testcase_05 AC 531 ms
145,624 KB
testcase_06 AC 534 ms
145,624 KB
testcase_07 AC 181 ms
94,576 KB
testcase_08 AC 427 ms
144,060 KB
testcase_09 AC 122 ms
79,524 KB
testcase_10 AC 242 ms
106,424 KB
testcase_11 AC 187 ms
93,760 KB
testcase_12 AC 147 ms
87,748 KB
testcase_13 AC 635 ms
121,300 KB
testcase_14 AC 712 ms
128,140 KB
testcase_15 AC 829 ms
138,048 KB
testcase_16 AC 438 ms
105,156 KB
testcase_17 AC 883 ms
142,392 KB
testcase_18 AC 328 ms
96,832 KB
testcase_19 AC 840 ms
138,924 KB
testcase_20 AC 317 ms
93,280 KB
testcase_21 AC 416 ms
102,864 KB
testcase_22 AC 784 ms
132,460 KB
testcase_23 AC 70 ms
74,448 KB
testcase_24 AC 78 ms
77,008 KB
testcase_25 AC 156 ms
87,708 KB
testcase_26 AC 504 ms
110,676 KB
testcase_27 AC 501 ms
110,020 KB
testcase_28 AC 818 ms
132,796 KB
testcase_29 AC 187 ms
83,440 KB
testcase_30 AC 827 ms
137,520 KB
testcase_31 AC 577 ms
120,636 KB
testcase_32 AC 427 ms
104,868 KB
testcase_33 AC 843 ms
137,876 KB
testcase_34 AC 345 ms
98,424 KB
testcase_35 AC 818 ms
139,568 KB
testcase_36 AC 80 ms
76,464 KB
testcase_37 AC 121 ms
77,804 KB
testcase_38 AC 92 ms
76,704 KB
testcase_39 AC 120 ms
77,564 KB
testcase_40 AC 59 ms
68,000 KB
testcase_41 AC 951 ms
145,328 KB
testcase_42 AC 363 ms
97,356 KB
testcase_43 AC 566 ms
112,460 KB
testcase_44 AC 262 ms
90,484 KB
testcase_45 AC 519 ms
111,628 KB
testcase_46 AC 35 ms
53,424 KB
testcase_47 AC 34 ms
53,428 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappush, heappop
import math
INF = float('inf')

N, M = map(int, input().split())
X, Y = map(int, input().split())
p = [list(map(int, input().split())) for _ in range(N)]
adj = [[] for _ in range(N)]
for i in range(M):
    P, Q = map(int, input().split())
    x1, y1 = p[P-1]
    x2, y2 = p[Q-1]
    adj[P-1].append((Q-1, math.sqrt((x1-x2)**2+(y1-y2)**2)))
    adj[Q-1].append((P-1, math.sqrt((x1-x2)**2+(y1-y2)**2)))

def dijkstra(s, n):
    dist = [INF] * n
    hq = [(0, s)]
    dist[s] = 0
    seen = [False] * n
    while hq:
        v = heappop(hq)[1]
        seen[v] = True
        for to, cost in adj[v]:
            if seen[to] == False and dist[v] + cost < dist[to]:
                dist[to] = dist[v] + cost
                heappush(hq, (dist[to], to))
    return dist
d = dijkstra(X-1, N)
print(d[Y-1])
0