We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 6d8fa87 commit 4fa4988Copy full SHA for 4fa4988
algorithms/dsu/naive_dsu.cpp
@@ -33,11 +33,11 @@ void make_set(int val)
33
34
int find_parent(int val)
35
{
36
- if(val == parent[val])
37
- {
38
- return val;
+ while (parent[val] != val) {
+ parent[val] = parent[parent[val]];
+ val = parent[val];
39
}
40
- return find_parent(parent[val]);
+ return val;
41
42
43
void union_set(int x, int y)
0 commit comments