結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー FukumotoFukumoto
提出日時 2020-06-08 19:49:00
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,365 ms / 2,000 ms
コード長 985 bytes
コンパイル時間 175 ms
コンパイル使用メモリ 11,000 KB
実行使用メモリ 117,756 KB
最終ジャッジ日時 2023-08-27 00:54:32
合計ジャッジ時間 29,891 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,620 KB
testcase_01 AC 17 ms
8,656 KB
testcase_02 AC 523 ms
60,384 KB
testcase_03 AC 954 ms
100,848 KB
testcase_04 AC 1,134 ms
99,612 KB
testcase_05 AC 789 ms
91,984 KB
testcase_06 AC 818 ms
91,848 KB
testcase_07 AC 194 ms
37,488 KB
testcase_08 AC 759 ms
117,756 KB
testcase_09 AC 76 ms
17,820 KB
testcase_10 AC 339 ms
57,228 KB
testcase_11 AC 232 ms
41,900 KB
testcase_12 AC 209 ms
31,776 KB
testcase_13 AC 828 ms
73,904 KB
testcase_14 AC 827 ms
83,052 KB
testcase_15 AC 1,064 ms
94,328 KB
testcase_16 AC 487 ms
53,508 KB
testcase_17 AC 1,310 ms
99,668 KB
testcase_18 AC 418 ms
43,008 KB
testcase_19 AC 931 ms
93,524 KB
testcase_20 AC 285 ms
33,140 KB
testcase_21 AC 566 ms
51,668 KB
testcase_22 AC 994 ms
88,340 KB
testcase_23 AC 25 ms
9,656 KB
testcase_24 AC 26 ms
9,684 KB
testcase_25 AC 184 ms
29,632 KB
testcase_26 AC 451 ms
53,220 KB
testcase_27 AC 478 ms
56,764 KB
testcase_28 AC 826 ms
86,724 KB
testcase_29 AC 154 ms
21,752 KB
testcase_30 AC 868 ms
91,664 KB
testcase_31 AC 715 ms
68,200 KB
testcase_32 AC 352 ms
45,836 KB
testcase_33 AC 1,126 ms
93,452 KB
testcase_34 AC 395 ms
43,368 KB
testcase_35 AC 804 ms
89,208 KB
testcase_36 AC 20 ms
9,056 KB
testcase_37 AC 23 ms
9,644 KB
testcase_38 AC 22 ms
9,028 KB
testcase_39 AC 22 ms
9,304 KB
testcase_40 AC 18 ms
8,912 KB
testcase_41 AC 1,365 ms
116,128 KB
testcase_42 AC 353 ms
41,344 KB
testcase_43 AC 597 ms
63,964 KB
testcase_44 AC 182 ms
28,572 KB
testcase_45 AC 653 ms
64,576 KB
testcase_46 AC 16 ms
8,432 KB
testcase_47 AC 16 ms
8,620 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappush, heappop, heapify
import sys
input = sys.stdin.readline

def main():
    N, M = list(map(int, input().split()))
    X, Y = list(map(int, input().split()))
    X -= 1; Y -= 1
    pq = [list(map(int, input().split())) for i in range(N)]
    g = [[] for i in range(N)]
    INF = float('inf')
    dist = [INF for i in range(N)]
    visited = [False] * N

    for i in range(M):
        p, q = list(map(int, input().split()))
        p -= 1; q -= 1

        px, py = pq[p]
        qx, qy = pq[q]

        d = ((px-qx)**2 + (py-qy)**2) **0.5
        g[p].append((d, q))
        g[q].append((d, p))

    q = g[X]
    heapify(q)
    dist[X] = 0
    visited[X] = True

    while q:
        c, v = heappop(q)

        if visited[v]: continue
        visited[v] = True
        dist[v] = c
        if v == Y:
            print(c)
            break

        for d, u in g[v]:
            if not visited[u]: heappush(q, (c+d, u))

if __name__ == '__main__':
    main()    
0