結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー Kiri8128Kiri8128
提出日時 2020-05-30 00:16:49
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,049 ms / 2,000 ms
コード長 913 bytes
コンパイル時間 181 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 152,712 KB
最終ジャッジ日時 2024-04-24 02:51:55
合計ジャッジ時間 24,590 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
53,120 KB
testcase_01 AC 44 ms
53,248 KB
testcase_02 AC 571 ms
112,824 KB
testcase_03 AC 821 ms
152,712 KB
testcase_04 AC 888 ms
152,104 KB
testcase_05 AC 678 ms
150,076 KB
testcase_06 AC 670 ms
149,948 KB
testcase_07 AC 148 ms
93,824 KB
testcase_08 AC 333 ms
143,448 KB
testcase_09 AC 99 ms
78,624 KB
testcase_10 AC 198 ms
105,876 KB
testcase_11 AC 162 ms
96,560 KB
testcase_12 AC 159 ms
94,848 KB
testcase_13 AC 772 ms
127,692 KB
testcase_14 AC 860 ms
133,828 KB
testcase_15 AC 1,016 ms
144,776 KB
testcase_16 AC 507 ms
111,196 KB
testcase_17 AC 996 ms
149,328 KB
testcase_18 AC 341 ms
101,660 KB
testcase_19 AC 984 ms
143,880 KB
testcase_20 AC 326 ms
94,668 KB
testcase_21 AC 402 ms
107,556 KB
testcase_22 AC 896 ms
137,860 KB
testcase_23 AC 62 ms
67,456 KB
testcase_24 AC 73 ms
70,400 KB
testcase_25 AC 142 ms
90,368 KB
testcase_26 AC 550 ms
113,392 KB
testcase_27 AC 549 ms
114,804 KB
testcase_28 AC 881 ms
141,204 KB
testcase_29 AC 167 ms
85,504 KB
testcase_30 AC 947 ms
142,944 KB
testcase_31 AC 638 ms
123,992 KB
testcase_32 AC 458 ms
106,880 KB
testcase_33 AC 1,049 ms
144,012 KB
testcase_34 AC 350 ms
102,132 KB
testcase_35 AC 934 ms
145,232 KB
testcase_36 AC 78 ms
71,168 KB
testcase_37 AC 108 ms
77,696 KB
testcase_38 AC 88 ms
73,472 KB
testcase_39 AC 113 ms
77,952 KB
testcase_40 AC 59 ms
63,104 KB
testcase_41 AC 966 ms
144,488 KB
testcase_42 AC 329 ms
97,820 KB
testcase_43 AC 536 ms
112,272 KB
testcase_44 AC 250 ms
90,408 KB
testcase_45 AC 560 ms
110,804 KB
testcase_46 AC 42 ms
53,008 KB
testcase_47 AC 44 ms
52,864 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heapify, heappush as hpush, heappop as hpop
from math import sqrt
import sys
input = lambda: sys.stdin.readline().rstrip()
N, M = map(int, input().split())
s, t = map(int, input().split())
s, t = s-1, t-1

L = []
for _ in range(N):
    a, b = map(int, input().split())
    L.append((a, b))

X = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    d = sqrt((L[a][0] - L[b][0]) ** 2 + (L[a][1] - L[b][1]) ** 2)
    X[a].append([b, d])
    X[b].append([a, d])

def dijkstra(n, E, i0=0):
    h = [[0, i0]]
    D = [-1] * n
    done = [0] * n
    D[i0] = 0
    
    while h:
        d, i = hpop(h)
        done[i] = 1
        for j, w in E[i]:
            nd = d + w
            if D[j] < 0 or D[j] > nd:
                if done[j] == 0:
                    hpush(h, [nd, j])
                    D[j] = nd
    return D

print(dijkstra(N, X, s)[t])

0