結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー wattaiheiwattaihei
提出日時 2020-05-29 21:41:31
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,888 ms / 2,000 ms
コード長 963 bytes
コンパイル時間 70 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 118,656 KB
最終ジャッジ日時 2024-04-23 20:52:19
合計ジャッジ時間 36,250 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
11,008 KB
testcase_01 AC 28 ms
10,880 KB
testcase_02 AC 914 ms
64,256 KB
testcase_03 AC 1,304 ms
103,964 KB
testcase_04 AC 1,296 ms
103,044 KB
testcase_05 AC 1,120 ms
95,652 KB
testcase_06 AC 1,151 ms
95,644 KB
testcase_07 AC 312 ms
39,424 KB
testcase_08 AC 1,340 ms
118,656 KB
testcase_09 AC 120 ms
20,224 KB
testcase_10 AC 530 ms
58,752 KB
testcase_11 AC 375 ms
43,648 KB
testcase_12 AC 333 ms
31,232 KB
testcase_13 AC 1,109 ms
70,016 KB
testcase_14 AC 1,243 ms
79,872 KB
testcase_15 AC 1,422 ms
91,648 KB
testcase_16 AC 735 ms
50,048 KB
testcase_17 AC 1,612 ms
97,588 KB
testcase_18 AC 519 ms
39,296 KB
testcase_19 AC 1,430 ms
92,672 KB
testcase_20 AC 377 ms
34,304 KB
testcase_21 AC 650 ms
45,056 KB
testcase_22 AC 1,330 ms
86,144 KB
testcase_23 AC 39 ms
11,648 KB
testcase_24 AC 43 ms
11,776 KB
testcase_25 AC 310 ms
29,056 KB
testcase_26 AC 751 ms
55,708 KB
testcase_27 AC 794 ms
56,320 KB
testcase_28 AC 1,357 ms
84,888 KB
testcase_29 AC 190 ms
20,992 KB
testcase_30 AC 1,437 ms
91,392 KB
testcase_31 AC 953 ms
69,220 KB
testcase_32 AC 642 ms
49,536 KB
testcase_33 AC 1,438 ms
92,972 KB
testcase_34 AC 527 ms
41,088 KB
testcase_35 AC 1,442 ms
92,368 KB
testcase_36 AC 35 ms
11,392 KB
testcase_37 AC 40 ms
11,904 KB
testcase_38 AC 38 ms
11,392 KB
testcase_39 AC 38 ms
11,776 KB
testcase_40 AC 30 ms
11,008 KB
testcase_41 AC 1,888 ms
118,272 KB
testcase_42 AC 536 ms
43,904 KB
testcase_43 AC 944 ms
67,712 KB
testcase_44 AC 327 ms
31,616 KB
testcase_45 AC 915 ms
66,304 KB
testcase_46 AC 28 ms
10,880 KB
testcase_47 AC 27 ms
10,880 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