Skip to content
Snippets Groups Projects
Commit d70d38f6 authored by Bruno Freitas Tissei's avatar Bruno Freitas Tissei
Browse files

Fix disjoint_set

parent b3bbb77b
No related branches found
No related tags found
No related merge requests found
......@@ -9,13 +9,13 @@
*/
int par[MAX];
int rank[MAX];
int h[MAX];
int sz[MAX];
// Initialize element x
void make_set(int x) {
par[x] = x;
rank[x] = 0;
h[x] = 0;
sz[x] = 1;
}
......@@ -35,15 +35,15 @@ void union_set(int x, int y) {
if (xroot == yroot)
return;
if (rank[xroot] < rank[yroot]) {
if (h[xroot] < h[yroot]) {
par[xroot] = yroot;
sz[yroot] += sz[xroot];
} else if (rank[xroot] > rank[yroot]) {
} else if (h[xroot] > h[yroot]) {
par[yroot] = xroot;
sz[xroot] += sz[yroot];
} else {
par[yroot] = xroot;
sz[xroot] += sz[yroot];
rank[xroot]++;
h[xroot]++;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment