Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int sz[N];
- int parent[N];
- int find_set(int v) {
- if (parent[v] == v) return v;
- return parent[v] = find_set(v);
- }
- int make_set(int v) {
- parent[v] = v;
- sz[v] = 1;
- }
- int union_sets(int u, int v) {
- v = find_set(v);
- u = find_set(u);
- if (u == v) return;
- if (sz[u] < sz[v]) swap(u, v);
- parent[v] = u;
- sz[u] += sz[v];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement