結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー tamatotamato
提出日時 2020-05-29 21:36:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 786 ms / 2,000 ms
コード長 1,247 bytes
コンパイル時間 171 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 130,564 KB
最終ジャッジ日時 2024-04-23 20:34:21
合計ジャッジ時間 18,674 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
52,992 KB
testcase_01 AC 39 ms
52,864 KB
testcase_02 AC 423 ms
102,104 KB
testcase_03 AC 579 ms
130,564 KB
testcase_04 AC 578 ms
129,120 KB
testcase_05 AC 434 ms
129,384 KB
testcase_06 AC 437 ms
129,304 KB
testcase_07 AC 128 ms
86,528 KB
testcase_08 AC 318 ms
126,672 KB
testcase_09 AC 90 ms
78,976 KB
testcase_10 AC 171 ms
94,848 KB
testcase_11 AC 136 ms
87,296 KB
testcase_12 AC 160 ms
88,448 KB
testcase_13 AC 549 ms
112,384 KB
testcase_14 AC 611 ms
116,776 KB
testcase_15 AC 696 ms
123,284 KB
testcase_16 AC 391 ms
101,120 KB
testcase_17 AC 786 ms
128,060 KB
testcase_18 AC 306 ms
93,440 KB
testcase_19 AC 716 ms
125,124 KB
testcase_20 AC 243 ms
89,600 KB
testcase_21 AC 368 ms
98,432 KB
testcase_22 AC 658 ms
119,644 KB
testcase_23 AC 59 ms
64,768 KB
testcase_24 AC 68 ms
67,200 KB
testcase_25 AC 154 ms
84,096 KB
testcase_26 AC 391 ms
103,436 KB
testcase_27 AC 436 ms
103,040 KB
testcase_28 AC 677 ms
119,784 KB
testcase_29 AC 163 ms
82,816 KB
testcase_30 AC 689 ms
123,032 KB
testcase_31 AC 470 ms
110,236 KB
testcase_32 AC 347 ms
99,328 KB
testcase_33 AC 745 ms
124,400 KB
testcase_34 AC 317 ms
94,208 KB
testcase_35 AC 687 ms
125,052 KB
testcase_36 AC 69 ms
68,992 KB
testcase_37 AC 98 ms
77,312 KB
testcase_38 AC 71 ms
70,400 KB
testcase_39 AC 100 ms
77,312 KB
testcase_40 AC 51 ms
61,568 KB
testcase_41 AC 752 ms
127,564 KB
testcase_42 AC 265 ms
91,904 KB
testcase_43 AC 441 ms
103,628 KB
testcase_44 AC 212 ms
86,528 KB
testcase_45 AC 398 ms
102,400 KB
testcase_46 AC 39 ms
52,864 KB
testcase_47 AC 40 ms
53,120 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 1000000007
eps = 10**-9


def main():
    import sys
    import heapq
    from math import hypot
    input = sys.stdin.buffer.readline

    def dijkstra(adj, start):
        # adj: [[to, cost] * vertices], 0th index must be empty
        inf = float("inf")
        dist = [inf] * len(adj)
        dist[start] = 0
        q = []
        heapq.heappush(q, (0, start))
        while q:
            min_dist, v_from = heapq.heappop(q)
            if min_dist > dist[v_from]:
                continue
            v_tos = adj[v_from]
            for v_to, cost in v_tos:
                if min_dist + cost < dist[v_to]:
                    dist[v_to] = min_dist + cost
                    heapq.heappush(q, (dist[v_to], v_to))
        return dist

    N, M = map(int, input().split())
    s, t = map(int, input().split())
    X = []
    Y = []
    for _ in range(N):
        p, q = map(int, input().split())
        X.append(p)
        Y.append(q)
    adj = [[] for _ in range(N+1)]
    for _ in range(M):
        i, j = map(int, input().split())
        d = hypot(X[i-1] - X[j-1], Y[i-1] - Y[j-1])
        adj[i].append((j, d))
        adj[j].append((i, d))

    dist = dijkstra(adj, s)
    print(dist[t])


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