結果
問題 | No.1065 電柱 / Pole (Easy) |
ユーザー |
![]() |
提出日時 | 2020-10-05 22:37:55 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 831 ms / 2,000 ms |
コード長 | 3,902 bytes |
コンパイル時間 | 399 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 147,492 KB |
最終ジャッジ日時 | 2024-07-19 22:22:01 |
合計ジャッジ時間 | 20,970 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 43 ms
53,248 KB |
testcase_01 | AC | 38 ms
53,504 KB |
testcase_02 | AC | 497 ms
110,436 KB |
testcase_03 | AC | 581 ms
147,492 KB |
testcase_04 | AC | 576 ms
147,108 KB |
testcase_05 | AC | 412 ms
146,496 KB |
testcase_06 | AC | 393 ms
146,624 KB |
testcase_07 | AC | 132 ms
89,856 KB |
testcase_08 | AC | 292 ms
139,900 KB |
testcase_09 | AC | 97 ms
78,208 KB |
testcase_10 | AC | 172 ms
102,272 KB |
testcase_11 | AC | 147 ms
95,252 KB |
testcase_12 | AC | 131 ms
91,904 KB |
testcase_13 | AC | 535 ms
125,440 KB |
testcase_14 | AC | 616 ms
131,488 KB |
testcase_15 | AC | 737 ms
139,808 KB |
testcase_16 | AC | 413 ms
111,744 KB |
testcase_17 | AC | 774 ms
145,964 KB |
testcase_18 | AC | 322 ms
102,400 KB |
testcase_19 | AC | 738 ms
140,160 KB |
testcase_20 | AC | 250 ms
94,292 KB |
testcase_21 | AC | 344 ms
110,472 KB |
testcase_22 | AC | 670 ms
135,028 KB |
testcase_23 | AC | 61 ms
69,120 KB |
testcase_24 | AC | 65 ms
72,320 KB |
testcase_25 | AC | 132 ms
92,032 KB |
testcase_26 | AC | 417 ms
112,996 KB |
testcase_27 | AC | 490 ms
114,048 KB |
testcase_28 | AC | 734 ms
139,404 KB |
testcase_29 | AC | 179 ms
86,928 KB |
testcase_30 | AC | 714 ms
139,868 KB |
testcase_31 | AC | 488 ms
120,780 KB |
testcase_32 | AC | 368 ms
105,856 KB |
testcase_33 | AC | 824 ms
139,672 KB |
testcase_34 | AC | 332 ms
102,244 KB |
testcase_35 | AC | 708 ms
143,012 KB |
testcase_36 | AC | 78 ms
74,368 KB |
testcase_37 | AC | 114 ms
77,568 KB |
testcase_38 | AC | 77 ms
74,240 KB |
testcase_39 | AC | 107 ms
77,824 KB |
testcase_40 | AC | 55 ms
64,256 KB |
testcase_41 | AC | 831 ms
141,192 KB |
testcase_42 | AC | 303 ms
97,056 KB |
testcase_43 | AC | 433 ms
110,976 KB |
testcase_44 | AC | 224 ms
89,216 KB |
testcase_45 | AC | 445 ms
110,080 KB |
testcase_46 | AC | 39 ms
52,864 KB |
testcase_47 | AC | 39 ms
53,120 KB |
ソースコード
import sys input=sys.stdin.readline def I(): return int(input()) def MI(): return map(int, input().split()) def LI(): return list(map(int, input().split())) def main(): mod=10**9+7 ########################################## import heapq class Dijkstra(): """ ・有向 / 無向は問わない(無向の場合は,逆向きの辺もたす) ・負のコストがない場合のみ ・計算量はO(E log|V|) ・heapを使うことで頂点を走査する必要がなくなる(代わりに,距離更新したものは確定でなくともqueに入れておく) ・復元なし """ #最短のpathをたす class Edge(): #重み付き有向辺 def __init__(self, _to, _cost): self.to =_to self.cost = _cost def __init__(self, V): #引数Vは頂点数 self.inf=10**20 self.G = [[] for _ in range(V)] #隣接リストG[u][i]が頂点uのi番目の辺 self. _E = 0 #辺の数 self._V = V #頂点数 #proparty - 辺の数 def E(self): return self._E #proparty - 頂点数 def V(self): return self._V def add(self, _from, _to, _cost): #2頂点と辺のコストを追加 self.G[_from].append(self.Edge(_to,_cost)) self._E +=1 def add2(self, _from, _to, _cost): #2頂点と辺のコスト(無向)を追加 self.G[_from].append(self.Edge(_to, _cost)) self.G[_to].append(self.Edge(_from, _cost)) self._E +=2 def shortest_path(self,s):#,g): #始点sから頂点iまでの最短経路長のリストを返す que = [] #priority queue d = [self.inf] * self.V() #prev = [None]*self.V() #prev[j]は,sからjへ最短経路で行くときのjの一つ前の場所 #復元で使う d[s] = 0 heapq.heappush(que,(0,s)) #始点の距離と頂点番号をヒープに追加 while len(que)!=0: #キューに格納されてある中で一番コストが小さい頂点を取り出す cost,v = heapq.heappop(que) #キューに格納された最短経路長候補がdの距離よりも大きい場合に処理をスキップ if d[v] < cost: continue #頂点vに隣接する各頂点iに対して,vを経由した場合の距離を計算して,これがd[i]よりも小さい場合に更新 for i in range(len(self.G[v])): e = self.G[v][i] #vのi個目の隣接辺 if d[e.to] > d[v] + e.cost: d[e.to] = d[v] + e.cost #更新 #prev[e.to] = v #復元で使う heapq.heappush(que,(d[e.to],e.to)) #queに新たな最短経路長候補を追加 """#sからgまでの最短経路 path = [] pos = g #今いる場所,ゴールで初期化 for _ in range(self.V()+1): path.append(pos) if pos == s: break #print("pos:",format(pos)) pos = prev[pos] path.reverse() #print(path)""" return d#,path ######################## N,M=MI() djk=Dijkstra(N) X,Y=MI() X-=1 Y-=1 p=[0]*N q=[0]*N for i in range(N): p[i],q[i]=MI() for i in range(M): P,Q=MI() P-=1 Q-=1 d=(p[P]-p[Q])**2 + (q[P]-q[Q])**2 d=d**0.5 djk.add2(P,Q,d) d=djk.shortest_path(X) ans=d[Y] print(ans) main()