結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー SalmonizeSalmonize
提出日時 2020-05-29 21:40:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 981 ms / 2,000 ms
コード長 1,058 bytes
コンパイル時間 286 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 138,428 KB
最終ジャッジ日時 2024-04-23 20:42:56
合計ジャッジ時間 22,713 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
53,248 KB
testcase_01 AC 43 ms
52,992 KB
testcase_02 AC 559 ms
107,920 KB
testcase_03 AC 652 ms
138,424 KB
testcase_04 AC 653 ms
138,428 KB
testcase_05 AC 454 ms
137,148 KB
testcase_06 AC 456 ms
137,272 KB
testcase_07 AC 154 ms
90,112 KB
testcase_08 AC 367 ms
136,832 KB
testcase_09 AC 110 ms
82,320 KB
testcase_10 AC 211 ms
103,424 KB
testcase_11 AC 166 ms
94,848 KB
testcase_12 AC 149 ms
87,040 KB
testcase_13 AC 730 ms
117,220 KB
testcase_14 AC 761 ms
122,900 KB
testcase_15 AC 868 ms
130,912 KB
testcase_16 AC 474 ms
102,712 KB
testcase_17 AC 952 ms
135,800 KB
testcase_18 AC 383 ms
95,592 KB
testcase_19 AC 854 ms
132,824 KB
testcase_20 AC 297 ms
91,192 KB
testcase_21 AC 438 ms
99,840 KB
testcase_22 AC 842 ms
127,616 KB
testcase_23 AC 62 ms
66,048 KB
testcase_24 AC 70 ms
68,992 KB
testcase_25 AC 142 ms
86,784 KB
testcase_26 AC 498 ms
106,696 KB
testcase_27 AC 550 ms
106,380 KB
testcase_28 AC 864 ms
126,872 KB
testcase_29 AC 191 ms
83,456 KB
testcase_30 AC 881 ms
131,028 KB
testcase_31 AC 594 ms
115,188 KB
testcase_32 AC 457 ms
102,244 KB
testcase_33 AC 963 ms
132,512 KB
testcase_34 AC 404 ms
95,984 KB
testcase_35 AC 880 ms
133,288 KB
testcase_36 AC 79 ms
70,656 KB
testcase_37 AC 116 ms
76,928 KB
testcase_38 AC 84 ms
71,936 KB
testcase_39 AC 113 ms
77,696 KB
testcase_40 AC 56 ms
62,208 KB
testcase_41 AC 981 ms
138,240 KB
testcase_42 AC 345 ms
95,832 KB
testcase_43 AC 560 ms
108,672 KB
testcase_44 AC 256 ms
88,704 KB
testcase_45 AC 535 ms
108,672 KB
testcase_46 AC 42 ms
52,736 KB
testcase_47 AC 43 ms
52,992 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys, heapq as hq

readline = sys.stdin.readline

ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))

def dijkstra(G, s, t=None):
    """
    G[v] = [(x1, c1), (x2, c2), ...]
    """
    dist = [-1]*len(G)
    dist[s] = 0
    q = [(0, s)]
    while q:
        d, v = hq.heappop(q)
        if d > dist[v]: continue
        for x, c in G[v]:
            if dist[x] < 0 or dist[x] > d + c:
                dist[x] = d + c
                hq.heappush(q, (d + c, x))
    if t is None:
        return dist
    else:
        return dist[t]

def solve():
    n, m = nm()
    X, Y = nm()
    X -= 1; Y -= 1
    points = [tuple(nm()) for _ in range(n)]
    G = [list() for _ in range(n)]
    for _ in range(m):
        u, v = nm()
        u -= 1; v -= 1
        p, q = points[u]
        r, s = points[v]
        c = ((p - r)**2 + (q - s)**2) ** .5
        G[u].append((v, c))
        G[v].append((u, c))
    print(dijkstra(G, X, Y))
    return

solve()
0