#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; template using V = vector; template using PQ = priority_queue, greater >; ll isqrt(ll n) { double rn = sqrt(double(n)); ll ok = max(0ll, (ll)(rn - 5.0)); ll ng = (ll)(rn + 5.0); while (ng - ok > 1ll) { ll 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) { ll r1 = squ(p[i][0]) + squ(p[i][1]); rep(j, i + 1, n) { ll r2 = squ(p[j][0]) + squ(p[j][1]); ll d = 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); } que.push({ d,(ll)i,(ll)j }); } } ll 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; }