結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー tcltktcltk
提出日時 2021-01-31 04:04:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,069 ms / 2,000 ms
コード長 1,306 bytes
コンパイル時間 293 ms
コンパイル使用メモリ 87,220 KB
実行使用メモリ 140,588 KB
最終ジャッジ日時 2023-09-11 00:27:43
合計ジャッジ時間 33,224 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 200 ms
80,984 KB
testcase_01 AC 198 ms
81,048 KB
testcase_02 AC 724 ms
111,996 KB
testcase_03 AC 893 ms
140,224 KB
testcase_04 AC 897 ms
140,256 KB
testcase_05 AC 618 ms
140,588 KB
testcase_06 AC 618 ms
140,400 KB
testcase_07 AC 309 ms
97,136 KB
testcase_08 AC 473 ms
136,960 KB
testcase_09 AC 261 ms
87,096 KB
testcase_10 AC 341 ms
106,536 KB
testcase_11 AC 303 ms
96,940 KB
testcase_12 AC 300 ms
95,804 KB
testcase_13 AC 783 ms
121,476 KB
testcase_14 AC 840 ms
126,428 KB
testcase_15 AC 941 ms
134,984 KB
testcase_16 AC 580 ms
108,912 KB
testcase_17 AC 999 ms
139,100 KB
testcase_18 AC 560 ms
102,532 KB
testcase_19 AC 947 ms
135,420 KB
testcase_20 AC 438 ms
98,836 KB
testcase_21 AC 522 ms
107,000 KB
testcase_22 AC 894 ms
130,616 KB
testcase_23 AC 218 ms
84,540 KB
testcase_24 AC 223 ms
84,512 KB
testcase_25 AC 283 ms
95,224 KB
testcase_26 AC 583 ms
111,700 KB
testcase_27 AC 643 ms
112,888 KB
testcase_28 AC 936 ms
130,836 KB
testcase_29 AC 339 ms
91,640 KB
testcase_30 AC 923 ms
133,928 KB
testcase_31 AC 688 ms
119,440 KB
testcase_32 AC 554 ms
107,444 KB
testcase_33 AC 1,069 ms
135,432 KB
testcase_34 AC 521 ms
103,516 KB
testcase_35 AC 914 ms
136,516 KB
testcase_36 AC 233 ms
84,544 KB
testcase_37 AC 265 ms
86,000 KB
testcase_38 AC 235 ms
84,444 KB
testcase_39 AC 258 ms
85,880 KB
testcase_40 AC 216 ms
84,120 KB
testcase_41 AC 1,018 ms
139,752 KB
testcase_42 AC 521 ms
101,168 KB
testcase_43 AC 631 ms
112,932 KB
testcase_44 AC 396 ms
95,060 KB
testcase_45 AC 613 ms
112,848 KB
testcase_46 AC 202 ms
81,000 KB
testcase_47 AC 205 ms
81,036 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#region Header
#!/usr/bin/env python3
# from typing import *

import sys
import io
import math
import collections
import decimal
import itertools
import bisect
import heapq

def input():
    return sys.stdin.readline()[:-1]

sys.setrecursionlimit(1000000)
#endregion

# _INPUT = """# paste here...
# """
# sys.stdin = io.StringIO(_INPUT)



def main():
    N, M = map(int, input().split())
    X, Y = map(lambda x: int(x)-1, input().split())
    G = [list() for _ in range(N)]
    P = []
    for _ in range(N):
        _x, _y = map(int, input().split())
        P.append((_x, _y))
    for _ in range(M):
        _p, _q = map(lambda x: int(x)-1, input().split())
        d = math.sqrt((P[_p][0] - P[_q][0]) ** 2 + (P[_p][1] - P[_q][1]) ** 2)
        G[_p].append((_q, d))
        G[_q].append((_p, d))

    # K を始点とする
    dist = [10**20 for _ in range(N)]
    hq = []
    heapq.heappush(hq, (0, X))
    dist[X] = 0
    while hq:
        d, p = heapq.heappop(hq)
        if d > dist[p]:
            continue
        for (p1, w1) in G[p]:
            d1 = dist[p] + w1
            if d1 < dist[p1]:
                dist[p1] = d1
                heapq.heappush(hq, (dist[p1], p1))

    print(dist[Y])

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