/** GOKURI */ #include #include #include #include #include #include #include #include #include #include using namespace std; #define FNAME "rect.txt" #define cin fin struct rect { int l, u, r, d; }; bool intersects( const rect& a, const rect& b ) { bool yoko = (a.l<=b.l && b.l<=a.r) || (a.l<=b.r && b.r<=a.r) || (b.l<=a.l && a.l<=b.r) || (b.l<=a.r && a.r<=b.r); bool tate = (a.d<=b.d && b.d<=a.u) || (a.d<=b.u && b.u<=a.u) || (b.d<=a.d && a.d<=b.u) || (b.d<=a.u && a.u<=b.u); return yoko&&tate; } template, class SETSIZE=map > class unionfind { typedef MAP NLink; typedef typename NLink::iterator NLinkIter; NLink gf; SETSIZE size; public: inline int getsize(T a) { return size[a] + 1; } T find_set(T a) { NLinkIter oit = gf.find(a); if(oit == gf.end()) return a; NLinkIter it, pit, nit; for(pit = it = oit; it != gf.end(); ) { pit = it; it = gf.find(it->second); } for(it = oit; it != gf.end(); it = nit) { nit = gf.find(it->second); it->second = pit->second; } return pit->second; } inline void link(T x, T y) { if(size[x] > size[y]) { gf[y] = x; size[x] += size[y] + 1; } else { gf[x] = y; size[y] += size[x] + 1; } } inline void union_set(T x, T y) { T fx = find_set(x); T fy = find_set(y); if(fx != fy) link(fx, fy); } unionfind() {} ~unionfind() {} }; int solve(const vector& rcts) { unionfind uf; for(int i=0; i counter; for(int i=0; i> N; while(N--) { int nr; cin >> nr; vector rcts; for(int i = 0; i < nr; i++) { rect r; cin >> r.l >> r.u >> r.r >> r.d; if(r.l > r.r) swap(r.l, r.r); if(r.u < r.d) swap(r.u, r.d); rcts.push_back(r); } cout << solve(rcts) << endl; } return 0; }