-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1277.py
52 lines (43 loc) · 1.27 KB
/
1277.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import sys
import heapq
from math import sqrt
input = sys.stdin.readline
INF = 200_000
EMPTY_SPOT = (-1, -1)
X = 0
Y = 1
def solution() -> float:
graph = [[INF for y in range(n + 1)] for x in range(n + 1)]
for i in range(1, n + 1):
for j in range(i + 1, n + 1):
dist = sqrt((sites[i][X] - sites[j][X])**2 + (sites[i][Y] - sites[j][Y])**2)
graph[i][j] = dist
graph[j][i] = dist
for a, b in is_cable:
graph[a][b] = 0
graph[b][a] = 0
is_visited = [False] * (n + 1)
START = 1
FINISH = n
heap = [(0, START)]
while len(heap):
dist, current = heapq.heappop(heap)
if is_visited[current]:
continue
is_visited[current] = True
if current == FINISH:
return dist
for next_node, weight in enumerate(graph[current]):
if weight <= m:
heapq.heappush(heap, (dist + weight, next_node))
if __name__ == '__main__':
n, w = map(int, input().split())
m = float(input())
sites = [EMPTY_SPOT]
for i in range(n):
sites.append(tuple(map(int, input().split())))
is_cable = []
for j in range(w):
is_cable.append(tuple(map(int, input().split())))
sol = solution()
print(int(1000 * sol))