void make_set(int v) { parent[v] = v; } int find_set(int v) { if (v == parent[v]) return v; return find_set(parent[v]); } void union_sets(int a, int b) { a = find_set(a); b = find_set(b); if (a != b) parent[b] = a; } is a naive implementation of disjoint set union algorithm, according to a article now i don't understand that if parent[3] = 1 and parent[2] = 1 and parent[1] = 1 after using union_sets(1, 2); union_sets(2, 3); but on the visual represntaiton of the set 3 should be the child of 2 but parent[3] is 1.