結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー O2MTO2MT
提出日時 2020-08-31 14:22:19
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 953 ms / 2,000 ms
コード長 1,008 bytes
コンパイル時間 164 ms
コンパイル使用メモリ 82,236 KB
実行使用メモリ 143,280 KB
最終ジャッジ日時 2024-04-27 18:15:37
合計ジャッジ時間 22,825 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
53,452 KB
testcase_01 AC 44 ms
54,412 KB
testcase_02 AC 548 ms
109,868 KB
testcase_03 AC 716 ms
143,280 KB
testcase_04 AC 690 ms
142,520 KB
testcase_05 AC 523 ms
139,052 KB
testcase_06 AC 523 ms
139,044 KB
testcase_07 AC 192 ms
93,736 KB
testcase_08 AC 452 ms
140,748 KB
testcase_09 AC 126 ms
80,920 KB
testcase_10 AC 254 ms
105,184 KB
testcase_11 AC 200 ms
95,188 KB
testcase_12 AC 171 ms
87,232 KB
testcase_13 AC 681 ms
118,744 KB
testcase_14 AC 746 ms
125,700 KB
testcase_15 AC 840 ms
136,060 KB
testcase_16 AC 469 ms
104,304 KB
testcase_17 AC 887 ms
140,244 KB
testcase_18 AC 357 ms
96,452 KB
testcase_19 AC 832 ms
137,488 KB
testcase_20 AC 313 ms
93,160 KB
testcase_21 AC 403 ms
101,020 KB
testcase_22 AC 815 ms
129,708 KB
testcase_23 AC 73 ms
74,512 KB
testcase_24 AC 82 ms
77,388 KB
testcase_25 AC 163 ms
87,104 KB
testcase_26 AC 492 ms
109,432 KB
testcase_27 AC 524 ms
108,572 KB
testcase_28 AC 825 ms
129,884 KB
testcase_29 AC 208 ms
84,284 KB
testcase_30 AC 841 ms
134,864 KB
testcase_31 AC 594 ms
118,448 KB
testcase_32 AC 442 ms
104,668 KB
testcase_33 AC 913 ms
135,876 KB
testcase_34 AC 390 ms
97,868 KB
testcase_35 AC 832 ms
137,456 KB
testcase_36 AC 88 ms
76,716 KB
testcase_37 AC 135 ms
78,496 KB
testcase_38 AC 97 ms
77,192 KB
testcase_39 AC 128 ms
77,632 KB
testcase_40 AC 62 ms
65,684 KB
testcase_41 AC 953 ms
141,708 KB
testcase_42 AC 358 ms
97,500 KB
testcase_43 AC 535 ms
110,328 KB
testcase_44 AC 269 ms
90,344 KB
testcase_45 AC 523 ms
109,924 KB
testcase_46 AC 40 ms
53,928 KB
testcase_47 AC 39 ms
53,532 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import sqrt
import heapq

def dijkstra(s, h, graph):
    n = len(graph)-1
    dist = [float("inf") for i in range(n+1)]
    dist[s] = 0
    pq = []
    heapq.heapify(pq)
    heapq.heappush(pq, (0, s))
    while pq:
        mini_dis, node = heapq.heappop(pq)
        if dist[node] < mini_dis:
            continue
        for w, point in graph[node]:
            if dist[point] < w:
                continue
            newlen = dist[node]+w
            if newlen < dist[point]:
                heapq.heappush(pq, (newlen, point))
                dist[point] = newlen
    return dist

N,M = map(int,input().split())
X,Y = map(int,input().split())
l = [[] for _ in range(N+1)] 
d =  [[] for _ in range(N+1)] 
for i in range(1,N+1):
  a,b = map(int,input().split())
  d[i].append(a)
  d[i].append(b)

for _ in range(M):
  a,b = map(int,input().split())
  dist = sqrt((d[a][0]-d[b][0])**2 + (d[a][1]-d[b][1])**2)
  l[a].append((dist,b))
  l[b].append((dist,a))
  
ans = dijkstra(X, Y, l)

print(ans[Y])
0