結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー rlangevinrlangevin
提出日時 2023-02-05 12:16:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 596 ms / 2,000 ms
コード長 1,298 bytes
コンパイル時間 249 ms
コンパイル使用メモリ 87,052 KB
実行使用メモリ 134,912 KB
最終ジャッジ日時 2023-09-17 05:12:31
合計ジャッジ時間 15,847 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
71,540 KB
testcase_01 AC 62 ms
71,332 KB
testcase_02 AC 352 ms
104,612 KB
testcase_03 AC 435 ms
134,488 KB
testcase_04 AC 495 ms
133,760 KB
testcase_05 AC 364 ms
134,912 KB
testcase_06 AC 359 ms
134,676 KB
testcase_07 AC 126 ms
89,924 KB
testcase_08 AC 252 ms
130,172 KB
testcase_09 AC 100 ms
79,028 KB
testcase_10 AC 170 ms
100,628 KB
testcase_11 AC 133 ms
89,584 KB
testcase_12 AC 116 ms
88,400 KB
testcase_13 AC 406 ms
116,284 KB
testcase_14 AC 413 ms
121,244 KB
testcase_15 AC 508 ms
129,664 KB
testcase_16 AC 264 ms
103,548 KB
testcase_17 AC 583 ms
133,600 KB
testcase_18 AC 252 ms
96,612 KB
testcase_19 AC 459 ms
128,440 KB
testcase_20 AC 221 ms
90,756 KB
testcase_21 AC 256 ms
101,580 KB
testcase_22 AC 449 ms
124,836 KB
testcase_23 AC 79 ms
76,904 KB
testcase_24 AC 79 ms
76,544 KB
testcase_25 AC 116 ms
88,400 KB
testcase_26 AC 274 ms
105,460 KB
testcase_27 AC 265 ms
106,012 KB
testcase_28 AC 387 ms
125,088 KB
testcase_29 AC 158 ms
84,548 KB
testcase_30 AC 409 ms
127,336 KB
testcase_31 AC 394 ms
113,644 KB
testcase_32 AC 220 ms
99,720 KB
testcase_33 AC 532 ms
130,096 KB
testcase_34 AC 253 ms
96,616 KB
testcase_35 AC 374 ms
128,892 KB
testcase_36 AC 79 ms
77,044 KB
testcase_37 AC 95 ms
78,088 KB
testcase_38 AC 87 ms
76,984 KB
testcase_39 AC 83 ms
76,932 KB
testcase_40 AC 72 ms
75,296 KB
testcase_41 AC 596 ms
130,348 KB
testcase_42 AC 222 ms
94,276 KB
testcase_43 AC 295 ms
105,784 KB
testcase_44 AC 167 ms
88,276 KB
testcase_45 AC 347 ms
104,888 KB
testcase_46 AC 63 ms
71,168 KB
testcase_47 AC 62 ms
71,284 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline = sys.stdin.readline
from math import *
from heapq import heappush, heappop
inf = float('inf')


def naive_dijkstra(s, g, N):
    # ゴールがない場合はg=-1とする。

    dist = [inf] * N
    mindist = [inf] * N
    seen = [False] * N
    Q = [(0, s)]
    while Q:
        c, m = heappop(Q)
        if seen[m]:
            continue
        seen[m] = True
        dist[m] = c
        if m == g:
            return dist

        #------heapをアップデートする。--------
        for u, C in G[m]:
            if seen[u]:
                continue
            newdist = dist[m] + C

            #------------------------------------
            if newdist >= mindist[u]:
                continue
            mindist[u] = newdist
            heappush(Q, (newdist, u))
    return dist

def dist(i, j):
    return sqrt((P[i] - P[j]) ** 2 + (Q[i] - Q[j]) ** 2)

N, M = map(int, readline().split())
X, Y = map(int, readline().split())
X, Y = X - 1, Y - 1
P, Q = [0] * N, [0] * N
for i in range(N):
    P[i], Q[i] = map(int, readline().split())
    
G = [[] for i in range(N)]
for i in range(M):
    p, q = map(int, readline().split())
    p, q = p - 1, q - 1
    G[p].append((q, dist(p, q)))
    G[q].append((p, dist(p, q)))
    
D = naive_dijkstra(X, Y, N)
print(D[Y])
0