結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー SalmonizeSalmonize
提出日時 2020-05-29 21:39:37
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,284 ms / 2,000 ms
コード長 1,059 bytes
コンパイル時間 225 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 106,240 KB
最終ジャッジ日時 2024-04-23 20:40:57
合計ジャッジ時間 26,301 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
10,752 KB
testcase_01 AC 30 ms
10,880 KB
testcase_02 AC 626 ms
58,240 KB
testcase_03 AC 959 ms
97,956 KB
testcase_04 AC 939 ms
96,652 KB
testcase_05 AC 785 ms
89,376 KB
testcase_06 AC 778 ms
89,376 KB
testcase_07 AC 214 ms
35,968 KB
testcase_08 AC 744 ms
106,240 KB
testcase_09 AC 87 ms
18,944 KB
testcase_10 AC 340 ms
53,120 KB
testcase_11 AC 250 ms
39,808 KB
testcase_12 AC 235 ms
31,232 KB
testcase_13 AC 779 ms
66,816 KB
testcase_14 AC 892 ms
75,904 KB
testcase_15 AC 1,076 ms
87,424 KB
testcase_16 AC 519 ms
48,512 KB
testcase_17 AC 1,180 ms
92,160 KB
testcase_18 AC 371 ms
38,656 KB
testcase_19 AC 1,060 ms
86,272 KB
testcase_20 AC 265 ms
32,384 KB
testcase_21 AC 473 ms
44,288 KB
testcase_22 AC 1,006 ms
81,920 KB
testcase_23 AC 34 ms
11,520 KB
testcase_24 AC 37 ms
11,648 KB
testcase_25 AC 209 ms
28,800 KB
testcase_26 AC 545 ms
52,352 KB
testcase_27 AC 573 ms
54,272 KB
testcase_28 AC 1,027 ms
80,960 KB
testcase_29 AC 136 ms
20,736 KB
testcase_30 AC 1,036 ms
86,220 KB
testcase_31 AC 692 ms
65,000 KB
testcase_32 AC 449 ms
46,964 KB
testcase_33 AC 1,100 ms
88,576 KB
testcase_34 AC 382 ms
39,936 KB
testcase_35 AC 1,055 ms
87,668 KB
testcase_36 AC 31 ms
11,136 KB
testcase_37 AC 35 ms
11,776 KB
testcase_38 AC 32 ms
11,136 KB
testcase_39 AC 34 ms
11,776 KB
testcase_40 AC 28 ms
11,008 KB
testcase_41 AC 1,284 ms
105,856 KB
testcase_42 AC 348 ms
40,192 KB
testcase_43 AC 642 ms
61,184 KB
testcase_44 AC 215 ms
29,312 KB
testcase_45 AC 633 ms
59,648 KB
testcase_46 AC 26 ms
10,752 KB
testcase_47 AC 25 ms
10,880 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