--- tags: codebook --- {%hackmd theme-dark %} # disjoint set ```cpp= #include<iostream> #include<vector> #include<numeric> #include<algorithm> #define endl '\n' using namespace std; vector<int> vec; int find(int x){ return (x==vec[x]?x:(vec[x]=find(vec[x]))); } void join(int x,int y){ vec[find(x)]=find(y); } void update(int x){ vec[x]=find(x); } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int n; while(cin>>n){ vec.resize(n); iota(vec.begin(),vec.end(),0); } return 0; } ```