#include #include #include #define rep(i, l, n) for (int i = (l); i < (n); i++) #define squ(n) (n) * (n) using namespace std; using namespace atcoder; using ll = long long; using u64 = unsigned long long; template using V = vector; template using PQ = priority_queue, greater >; u64 isqrt(u64 n) { u64 ok = 0ll; u64 ng = 4000000000ll; while (ng - ok > 1ll) { u64 mid = (ok + ng) >> 1ll; if (mid * mid <= n) { ok = mid; } else { ng = mid; } } return ok; } int main(void) { int n; cin >> n; V > p(n, V(3)); rep(i, 0, n) { ll x, y, t; cin >> x >> y >> t; p[i] = { x,y,t }; } PQ > que = {}; rep(i, 0, n-1) { u64 r1 = (u64)(squ(p[i][0]) + squ(p[i][1])); rep(j, i + 1, n) { u64 r2 = (u64)(squ(p[j][0]) + squ(p[j][1])); u64 d = (u64)(squ(p[i][0] - p[j][0]) + squ(p[i][1] - p[j][1])); if (p[i][2] != p[j][2]) { d = r1 + r2 - isqrt(4ll * r1 * r2); cout << r1 << ' ' << r2 << ' ' << isqrt(4ll * r1 * r2) << endl; } que.push({ d,(u64)i,(u64)j }); } } u64 ans = 0ll; dsu uni(n); while (uni.same(0, n - 1) == false) { V v = que.top(); que.pop(); ans = v[0]; uni.merge(v[1], v[2]); } cout << ans << endl; return 0; }