結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー O2MTO2MT
提出日時 2020-08-31 14:45:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 768 ms / 2,000 ms
コード長 1,002 bytes
コンパイル時間 394 ms
コンパイル使用メモリ 81,888 KB
実行使用メモリ 142,904 KB
最終ジャッジ日時 2024-04-27 18:39:04
合計ジャッジ時間 18,825 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
52,744 KB
testcase_01 AC 33 ms
53,156 KB
testcase_02 AC 421 ms
109,484 KB
testcase_03 AC 579 ms
142,904 KB
testcase_04 AC 567 ms
142,260 KB
testcase_05 AC 428 ms
138,668 KB
testcase_06 AC 426 ms
138,732 KB
testcase_07 AC 157 ms
93,672 KB
testcase_08 AC 362 ms
140,456 KB
testcase_09 AC 107 ms
80,856 KB
testcase_10 AC 203 ms
104,604 KB
testcase_11 AC 171 ms
95,248 KB
testcase_12 AC 143 ms
86,840 KB
testcase_13 AC 536 ms
118,892 KB
testcase_14 AC 586 ms
125,268 KB
testcase_15 AC 688 ms
135,800 KB
testcase_16 AC 377 ms
104,316 KB
testcase_17 AC 731 ms
140,124 KB
testcase_18 AC 283 ms
96,092 KB
testcase_19 AC 678 ms
136,972 KB
testcase_20 AC 246 ms
93,172 KB
testcase_21 AC 307 ms
100,892 KB
testcase_22 AC 648 ms
129,852 KB
testcase_23 AC 64 ms
74,380 KB
testcase_24 AC 70 ms
77,104 KB
testcase_25 AC 130 ms
86,956 KB
testcase_26 AC 383 ms
109,396 KB
testcase_27 AC 422 ms
108,800 KB
testcase_28 AC 662 ms
129,752 KB
testcase_29 AC 168 ms
84,496 KB
testcase_30 AC 675 ms
134,492 KB
testcase_31 AC 489 ms
118,592 KB
testcase_32 AC 344 ms
104,412 KB
testcase_33 AC 759 ms
135,896 KB
testcase_34 AC 299 ms
97,592 KB
testcase_35 AC 674 ms
137,200 KB
testcase_36 AC 76 ms
76,924 KB
testcase_37 AC 109 ms
78,320 KB
testcase_38 AC 83 ms
77,180 KB
testcase_39 AC 114 ms
77,936 KB
testcase_40 AC 57 ms
67,088 KB
testcase_41 AC 768 ms
141,544 KB
testcase_42 AC 291 ms
97,276 KB
testcase_43 AC 430 ms
110,332 KB
testcase_44 AC 210 ms
89,728 KB
testcase_45 AC 420 ms
110,048 KB
testcase_46 AC 35 ms
53,028 KB
testcase_47 AC 33 ms
53,508 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import sqrt
import heapq

def dijkstra(s, 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, l)

print(ans[Y])
0