import math import heapq def main(): n = int(input()) planets = [] for _ in range(n): x, y, t = map(int, input().split()) r = math.hypot(x, y) planets.append((x, y, t, r)) # Precompute all pairs' minimal distance squared edges = [[0.0] * n for _ in range(n)] for i in range(n): xi, yi, ti, ri = planets[i] for j in range(n): if i == j: continue xj, yj, tj, rj = planets[j] if ti != tj: d_sq = (ri - rj) ** 2 else: dx = xi - xj dy = yi - yj d_sq = dx * dx + dy * dy edges[i][j] = d_sq # Dijkstra's algorithm to find the minimal maximum edge weight INF = float('inf') dist = [INF] * n dist[0] = 0.0 # Starting at planet 1 (index 0) heap = [] heapq.heappush(heap, (0.0, 0)) while heap: current_max, u = heapq.heappop(heap) if u == n - 1: print(math.ceil(current_max)) return if current_max > dist[u]: continue for v in range(n): if v == u: continue new_max = max(current_max, edges[u][v]) if new_max < dist[v]: dist[v] = new_max heapq.heappush(heap, (new_max, v)) # If no path found (shouldn't happen as per problem constraints) print(-1) if __name__ == "__main__": main()