Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int maxN = 200010;
- int p[maxN],r[maxN];
- int __find__ (int a) {
- return p[a] = (p[a] == a ? a : __find__(p[a]));
- }
- void __union__ (int a,int b) {
- a = __find__(a);
- b = __find__(b);
- if (r[a] == r[b]) ++r[a];
- if (r[a] > r[b]) p[b] = a;
- else p[a] = b;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement