結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー wattaiheiwattaihei
提出日時 2020-05-29 21:42:57
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 824 ms / 2,000 ms
コード長 963 bytes
コンパイル時間 325 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 142,780 KB
最終ジャッジ日時 2024-04-23 20:57:34
合計ジャッジ時間 18,565 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,248 KB
testcase_01 AC 36 ms
52,608 KB
testcase_02 AC 449 ms
111,404 KB
testcase_03 AC 580 ms
141,800 KB
testcase_04 AC 555 ms
142,024 KB
testcase_05 AC 371 ms
138,412 KB
testcase_06 AC 387 ms
138,160 KB
testcase_07 AC 126 ms
91,356 KB
testcase_08 AC 301 ms
141,356 KB
testcase_09 AC 87 ms
82,176 KB
testcase_10 AC 178 ms
104,696 KB
testcase_11 AC 138 ms
96,128 KB
testcase_12 AC 117 ms
87,556 KB
testcase_13 AC 562 ms
119,112 KB
testcase_14 AC 636 ms
126,532 KB
testcase_15 AC 697 ms
135,236 KB
testcase_16 AC 352 ms
104,576 KB
testcase_17 AC 745 ms
140,520 KB
testcase_18 AC 274 ms
96,148 KB
testcase_19 AC 719 ms
137,464 KB
testcase_20 AC 247 ms
92,808 KB
testcase_21 AC 327 ms
100,572 KB
testcase_22 AC 681 ms
130,616 KB
testcase_23 AC 49 ms
66,816 KB
testcase_24 AC 54 ms
69,248 KB
testcase_25 AC 110 ms
86,808 KB
testcase_26 AC 390 ms
110,076 KB
testcase_27 AC 430 ms
109,312 KB
testcase_28 AC 714 ms
129,756 KB
testcase_29 AC 152 ms
83,556 KB
testcase_30 AC 709 ms
135,576 KB
testcase_31 AC 491 ms
118,640 KB
testcase_32 AC 350 ms
104,152 KB
testcase_33 AC 790 ms
136,992 KB
testcase_34 AC 336 ms
97,664 KB
testcase_35 AC 716 ms
135,976 KB
testcase_36 AC 61 ms
70,016 KB
testcase_37 AC 94 ms
77,824 KB
testcase_38 AC 65 ms
72,320 KB
testcase_39 AC 90 ms
77,444 KB
testcase_40 AC 46 ms
62,464 KB
testcase_41 AC 824 ms
142,780 KB
testcase_42 AC 275 ms
97,388 KB
testcase_43 AC 428 ms
111,616 KB
testcase_44 AC 207 ms
89,908 KB
testcase_45 AC 407 ms
110,664 KB
testcase_46 AC 36 ms
52,864 KB
testcase_47 AC 35 ms
52,480 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq as hp
import sys
input = sys.stdin.readline

INF = 10**18

N, M = map(int, input().split())
X, Y = map(int, input().split())
X -= 1; Y -= 1
XY = [list(map(int, input().split())) for _ in range(N)]
graph = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    a -= 1; b -= 1
    x1, y1 = XY[a]; x2, y2 = XY[b]
    d = ((x1-x2)**2 + (y1-y2)**2)**(0.5)
    graph[a].append((d, b))
    graph[b].append((d, a))



D = [INF for _ in range(N)] # 頂点iへの最短距離がD[i]
D[X] = 0 
q = [] # しまっていく優先度付きキュー
hp.heappush(q, (0, X))

while q:
    nd, np = hp.heappop(q) # 一番距離が近いものを取ってくる
    if D[np] < nd: # 追加した後の残骸は見ない
        continue
    for d, p in graph[np]:
        if D[p] > D[np] + d: # 隣接するやつの中で今よりも近くなれるなら更新
            D[p] = D[np] + d
            hp.heappush(q, (D[p], p))

print(D[Y])
0