Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions atcoder/dsu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ struct dsu {

int leader(int a) {
assert(0 <= a && a < _n);
if (parent_or_size[a] < 0) return a;
return parent_or_size[a] = leader(parent_or_size[a]);
return _leader(a);
}

int size(int a) {
Expand Down Expand Up @@ -69,6 +68,11 @@ struct dsu {
// root node: -1 * component size
// otherwise: parent
std::vector<int> parent_or_size;

int _leader(int a) {
if (parent_or_size[a] < 0) return a;
return parent_or_size[a] = _leader(parent_or_size[a]);
}
};

} // namespace atcoder
Expand Down
Loading