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 2df885d commit ad80e62Copy full SHA for ad80e62
atcoder/dsu.hpp
@@ -35,8 +35,7 @@ struct dsu {
35
36
int leader(int a) {
37
assert(0 <= a && a < _n);
38
- if (parent_or_size[a] < 0) return a;
39
- return parent_or_size[a] = leader(parent_or_size[a]);
+ return _leader(a);
40
}
41
42
int size(int a) {
@@ -69,6 +68,11 @@ struct dsu {
69
68
// root node: -1 * component size
70
// otherwise: parent
71
std::vector<int> parent_or_size;
+
72
+ int _leader(int a) {
73
+ if (parent_or_size[a] < 0) return a;
74
+ return parent_or_size[a] = _leader(parent_or_size[a]);
75
+ }
76
};
77
78
} // namespace atcoder
0 commit comments