- class dsu {
- public:
- vector<int> fa ;
- int n ;
- dsu(int _n) : n(_n){
- fa.resize(n);
- iota(fa.begin() ,fa.end() , 0);
- }
- inline int get(int x){
- if(x != fa[x])return fa[x] = get(fa[x]);
- else return x;
- }
- inline bool unite(int x , int y ){
- x = get(x);
- y = get(y);
- if(x == y)return 0 ;
- else {
- fa[x] = y ;
- return 1;
- }
-
- }
- };