import math import heapq def main(): N = int(input()) X = [] Y = [] T = [] r_i = [] for _ in range(N): x, y, t = map(int, input().split()) X.append(x) Y.append(y) T.append(t) r = math.hypot(x, y) r_i.append(r) # Precompute distance matrix d_matrix = [[0.0] * N for _ in range(N)] for i in range(N): for j in range(N): if i == j: d_matrix[i][j] = 0.0 else: if T[i] == T[j]: dx = X[i] - X[j] dy = Y[i] - Y[j] d = math.hypot(dx, dy) else: d = abs(r_i[i] - r_i[j]) d_matrix[i][j] = d d_matrix[j][i] = d # since undirected # Dijkstra's algorithm to find minimal maximum edge INF = float('inf') dist = [INF] * N dist[0] = 0.0 heap = [] heapq.heappush(heap, (0.0, 0)) while heap: current_max, u = heapq.heappop(heap) if u == N - 1: # Compute the square and round to integer print(int(round(current_max ** 2))) return if current_max > dist[u]: continue for v in range(N): if v == u: continue new_max = max(current_max, d_matrix[u][v]) if new_max < dist[v]: dist[v] = new_max heapq.heappush(heap, (new_max, v)) # If no path found (but problem states there is a path) print(0) if __name__ == "__main__": main()