結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー nephrologistnephrologist
提出日時 2020-05-30 11:04:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 794 ms / 2,000 ms
コード長 1,162 bytes
コンパイル時間 214 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 141,760 KB
最終ジャッジ日時 2024-04-24 21:51:03
合計ジャッジ時間 17,681 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
52,608 KB
testcase_01 AC 44 ms
52,992 KB
testcase_02 AC 348 ms
108,568 KB
testcase_03 AC 504 ms
140,636 KB
testcase_04 AC 583 ms
140,372 KB
testcase_05 AC 394 ms
141,760 KB
testcase_06 AC 413 ms
141,552 KB
testcase_07 AC 135 ms
89,728 KB
testcase_08 AC 305 ms
140,160 KB
testcase_09 AC 97 ms
78,592 KB
testcase_10 AC 180 ms
102,528 KB
testcase_11 AC 152 ms
96,640 KB
testcase_12 AC 115 ms
85,760 KB
testcase_13 AC 511 ms
118,100 KB
testcase_14 AC 521 ms
124,928 KB
testcase_15 AC 666 ms
133,488 KB
testcase_16 AC 333 ms
102,656 KB
testcase_17 AC 762 ms
138,764 KB
testcase_18 AC 306 ms
95,308 KB
testcase_19 AC 595 ms
133,396 KB
testcase_20 AC 262 ms
91,828 KB
testcase_21 AC 343 ms
99,316 KB
testcase_22 AC 637 ms
128,844 KB
testcase_23 AC 62 ms
64,896 KB
testcase_24 AC 61 ms
64,896 KB
testcase_25 AC 112 ms
85,888 KB
testcase_26 AC 331 ms
107,052 KB
testcase_27 AC 356 ms
107,064 KB
testcase_28 AC 517 ms
125,572 KB
testcase_29 AC 170 ms
82,816 KB
testcase_30 AC 531 ms
131,844 KB
testcase_31 AC 496 ms
117,512 KB
testcase_32 AC 271 ms
102,400 KB
testcase_33 AC 722 ms
135,524 KB
testcase_34 AC 303 ms
96,768 KB
testcase_35 AC 508 ms
131,880 KB
testcase_36 AC 63 ms
65,024 KB
testcase_37 AC 83 ms
72,448 KB
testcase_38 AC 67 ms
66,944 KB
testcase_39 AC 74 ms
69,632 KB
testcase_40 AC 49 ms
55,168 KB
testcase_41 AC 794 ms
141,524 KB
testcase_42 AC 283 ms
96,624 KB
testcase_43 AC 399 ms
110,720 KB
testcase_44 AC 194 ms
89,472 KB
testcase_45 AC 455 ms
109,984 KB
testcase_46 AC 44 ms
52,864 KB
testcase_47 AC 43 ms
52,992 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import sqrt
from heapq import heappush, heappop
import sys

input = sys.stdin.buffer.readline


def main():

    n, m = map(int, input().split())
    x, y = map(int, input().split())
    x -= 1
    y -= 1

    def kyori(a, b, c, d):
        return sqrt((a - c) ** 2 + (b - d) ** 2)

    XY = [list(map(int, input().split())) for _ in range(n)]
    graph = [[] for _ in range(n)]
    for _ in range(m):
        p, q = map(int, input().split())
        a, b = XY[p - 1]
        c, d = XY[q - 1]
        temp = kyori(a, b, c, d)
        graph[p - 1].append((temp, q - 1))
        graph[q - 1].append((temp, p - 1))

    edgelist = [(0, x)]
    dist = [10 ** 10] * n
    dist[x] = 0
    while edgelist:
        nowd, nowedge = heappop(edgelist)
        if nowedge == y:
            print(nowd)
            exit()
        if dist[nowedge] < nowd:
            continue
        for delta, nextedge in graph[nowedge]:
            if dist[nextedge] <= delta + nowd:
                continue
            dist[nextedge] = delta + nowd
            heappush(edgelist, (nowd + delta, nextedge))

    print("error")
    exit()


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