Advertisement
Guest User

Untitled

a guest
Nov 17th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.26 KB | None | 0 0
  1. void make_set (int v) {
  2.     parent[v] = v;
  3. }
  4.  
  5. int find_set (int v) {
  6.     if (v == parent[v])
  7.         return v;
  8.     return parent[v] = find_set (parent[v]);
  9. }
  10.  
  11. void union_sets (int a, int b) {
  12.     a = find_set (a);
  13.     b = find_set (b);
  14.     if (a != b)
  15.         parent[b] = a;
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement