結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー 双六双六
提出日時 2020-07-24 21:00:31
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,045 ms / 2,000 ms
コード長 1,257 bytes
コンパイル時間 810 ms
コンパイル使用メモリ 86,960 KB
実行使用メモリ 190,056 KB
最終ジャッジ日時 2023-09-08 02:45:12
合計ジャッジ時間 29,710 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
72,192 KB
testcase_01 AC 88 ms
72,056 KB
testcase_02 AC 620 ms
127,784 KB
testcase_03 AC 744 ms
164,812 KB
testcase_04 AC 737 ms
162,096 KB
testcase_05 AC 527 ms
165,344 KB
testcase_06 AC 509 ms
165,308 KB
testcase_07 AC 211 ms
104,984 KB
testcase_08 AC 442 ms
190,056 KB
testcase_09 AC 149 ms
85,224 KB
testcase_10 AC 263 ms
122,640 KB
testcase_11 AC 224 ms
110,684 KB
testcase_12 AC 198 ms
91,052 KB
testcase_13 AC 749 ms
129,820 KB
testcase_14 AC 829 ms
142,084 KB
testcase_15 AC 938 ms
155,344 KB
testcase_16 AC 543 ms
108,540 KB
testcase_17 AC 1,030 ms
160,160 KB
testcase_18 AC 432 ms
100,356 KB
testcase_19 AC 903 ms
157,124 KB
testcase_20 AC 328 ms
97,436 KB
testcase_21 AC 461 ms
104,532 KB
testcase_22 AC 915 ms
148,736 KB
testcase_23 AC 112 ms
78,016 KB
testcase_24 AC 117 ms
78,244 KB
testcase_25 AC 188 ms
88,400 KB
testcase_26 AC 567 ms
120,996 KB
testcase_27 AC 590 ms
117,720 KB
testcase_28 AC 956 ms
144,076 KB
testcase_29 AC 236 ms
86,276 KB
testcase_30 AC 940 ms
155,504 KB
testcase_31 AC 663 ms
133,772 KB
testcase_32 AC 487 ms
113,672 KB
testcase_33 AC 1,003 ms
157,464 KB
testcase_34 AC 438 ms
102,272 KB
testcase_35 AC 900 ms
155,600 KB
testcase_36 AC 119 ms
78,328 KB
testcase_37 AC 148 ms
79,780 KB
testcase_38 AC 122 ms
78,320 KB
testcase_39 AC 159 ms
79,900 KB
testcase_40 AC 106 ms
77,820 KB
testcase_41 AC 1,045 ms
187,908 KB
testcase_42 AC 384 ms
108,292 KB
testcase_43 AC 605 ms
130,668 KB
testcase_44 AC 294 ms
96,132 KB
testcase_45 AC 590 ms
125,828 KB
testcase_46 AC 92 ms
71,788 KB
testcase_47 AC 89 ms
71,956 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys; input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict
from heapq import heappop, heappush
INF = float('inf')

def getlist():
	return list(map(int, input().split()))

class Graph(object):
	def __init__(self):
		self.graph = defaultdict(list)

	def __len__(self):
		return len(self.graph)

	def add_edge(self, a, b, w):
		self.graph[a].append((b, w))

class Dijkstra(object):
	def __init__(self, graph, s):
		self.g = graph.graph
		self.dist = defaultdict(lambda: INF); self.dist[s] = 0
		self.Q = []
		heappush(self.Q, (self.dist[s], s))
		while self.Q:
			dist_u, u = heappop(self.Q)
			if self.dist[u] < dist_u:
				continue
			for v, w in self.g[u]:
				alt = dist_u + w
				if self.dist[v] > alt:
					self.dist[v] = alt
					heappush(self.Q, (alt, v))

#処理内容
def main():
	N, M = getlist()
	X, Y = getlist()
	X -= 1; Y -= 1
	node = []
	for i in range(N):
		p, q = getlist()
		node.append([p, q])

	G = Graph()
	for i in range(M):
		P, Q = getlist()
		P -= 1; Q -= 1
		x1, y1 = node[P]
		x2, y2 = node[Q]
		dist = ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5
		G.add_edge(P, Q, dist)
		G.add_edge(Q, P, dist)

	D = Dijkstra(G, X)
	ans = D.dist[Y]
	print(ans)

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