#include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; struct UnionFind { int ngroup; vector par; vector siz; UnionFind(int N) : par(N), siz(N) { ngroup = N; for(int i = 0; i < N; i++){ par[i] = i; siz[i] = 1; } } int root(int x) { if (par[x] == x) return x; return par[x] = root(par[x]); } int unite(int x, int y) { int rx = root(x); int ry = root(y); if (rx == ry) return rx; ngroup--; if (siz[rx] > siz[ry]) swap(rx, ry); par[rx] = ry; siz[ry] += siz[rx]; return ry; } bool same(int x, int y) { int rx = root(x); int ry = root(y); return rx == ry; } int size(int x){ return siz[root(x)]; } int group_count(){ return ngroup; } }; ll s(ll x){ return x*x; } ll isqrt(ll s){ ll l=0, r=3e9, c; while(r-l>1){ c = (l+r)/2; if (c*c <= s) l = c; else r = c; } return l; } int main(){ ll N, C, ans=0, R1, R2; cin >> N; vector> v; vector x(N), y(N), t(N); for (int i=0; i> x[i] >> y[i] >> t[i]; UnionFind tree(N+1); for (int i=0; i