結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー ayaoniayaoni
提出日時 2021-04-25 00:43:18
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,037 ms / 2,000 ms
コード長 1,888 bytes
コンパイル時間 339 ms
コンパイル使用メモリ 87,148 KB
実行使用メモリ 144,692 KB
最終ジャッジ日時 2023-09-17 13:53:44
合計ジャッジ時間 28,677 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
71,876 KB
testcase_01 AC 80 ms
71,564 KB
testcase_02 AC 598 ms
112,692 KB
testcase_03 AC 724 ms
141,000 KB
testcase_04 AC 713 ms
140,828 KB
testcase_05 AC 503 ms
137,912 KB
testcase_06 AC 502 ms
138,184 KB
testcase_07 AC 193 ms
93,924 KB
testcase_08 AC 452 ms
143,080 KB
testcase_09 AC 139 ms
81,424 KB
testcase_10 AC 255 ms
105,724 KB
testcase_11 AC 211 ms
97,968 KB
testcase_12 AC 188 ms
90,080 KB
testcase_13 AC 757 ms
119,880 KB
testcase_14 AC 812 ms
127,040 KB
testcase_15 AC 935 ms
135,788 KB
testcase_16 AC 551 ms
104,892 KB
testcase_17 AC 1,015 ms
140,984 KB
testcase_18 AC 428 ms
98,564 KB
testcase_19 AC 926 ms
136,696 KB
testcase_20 AC 344 ms
94,016 KB
testcase_21 AC 438 ms
101,876 KB
testcase_22 AC 886 ms
131,272 KB
testcase_23 AC 98 ms
77,052 KB
testcase_24 AC 109 ms
78,872 KB
testcase_25 AC 175 ms
86,064 KB
testcase_26 AC 545 ms
109,928 KB
testcase_27 AC 601 ms
110,340 KB
testcase_28 AC 928 ms
131,032 KB
testcase_29 AC 226 ms
85,848 KB
testcase_30 AC 942 ms
135,292 KB
testcase_31 AC 662 ms
119,992 KB
testcase_32 AC 507 ms
105,220 KB
testcase_33 AC 992 ms
136,512 KB
testcase_34 AC 455 ms
98,564 KB
testcase_35 AC 915 ms
137,496 KB
testcase_36 AC 116 ms
78,144 KB
testcase_37 AC 140 ms
78,560 KB
testcase_38 AC 120 ms
78,352 KB
testcase_39 AC 147 ms
78,976 KB
testcase_40 AC 91 ms
76,004 KB
testcase_41 AC 1,037 ms
144,692 KB
testcase_42 AC 403 ms
99,020 KB
testcase_43 AC 603 ms
113,356 KB
testcase_44 AC 306 ms
91,720 KB
testcase_45 AC 573 ms
112,440 KB
testcase_46 AC 79 ms
71,364 KB
testcase_47 AC 79 ms
71,680 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import heapq
sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def LS2(): return list(sys.stdin.readline().rstrip())


class Dijkstra_list():  # 1-based
    def __init__(self,N):
        self.N = N
        self.edges = [[] for _ in range(N+1)]

    def add(self, u, v, d, directed=False):
        if directed is False:  # 無向グラフの場合
            self.edges[u].append((v,d))
            self.edges[v].append((u,d))
        else:  # 有向グラフの場合
            self.edges[u].append((v,d))

    def delete(self, u, v):
        self.edges[u] = [_ for _ in self.edges[u] if _[0] != v]
        self.edges[v] = [_ for _ in self.edges[v] if _[0] != u]

    def search(self, s):  # sから各頂点までの最短距離
        inf = 10**18
        dist = [inf]*(self.N+1)
        dist[s] = 0
        q = []
        heapq.heappush(q, (0, s))
        v = [0]*(self.N+1)
        while q:
            k, u = heapq.heappop(q)
            if v[u]:
                continue
            v[u] = 1

            for uv, ud in self.edges[u]:
                if v[uv]:
                    continue
                vd = k + ud
                if dist[uv] > vd:
                    dist[uv] = vd
                    heapq.heappush(q, (vd, uv))
        return dist


N,M = MI()
X,Y = MI()
pos = [(0,0)]+[tuple(MI()) for _ in range(N)]

Di = Dijkstra_list(N)
for _ in range(M):
    P,Q = MI()
    x0,y0 = pos[P]
    x1,y1 = pos[Q]
    d = ((x0-x1)**2+(y0-y1)**2)**.5
    Di.add(P,Q,d,directed=False)

dist = Di.search(X)
ans = dist[Y]
print(ans)
0