--- 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; } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up