Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ll high[N];
- ll p[N]; // set p of i equal to i initially
- ll find(ll x)
- {
- if(p[x]!=x)
- p[x]=find(p[x]);
- return p[x];
- }
- void merge(ll x,ll y)
- {
- ll Px,Py;
- Px=find(x);
- Py=find(y);
- if(high[Px]>high[Py])
- p[Py]=Px;
- else
- p[Px]=Py;
- if(high[Px]==high[Py])
- high[Py]++;
- }
Advertisement
Add Comment
Please, Sign In to add comment