commit 55f537f6393e910be3212e4812560fcd072cd6f3
parent 55ae892793093808585469747344fb139da57a15
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date: Sun, 25 Feb 2024 14:47:53 +0000
Improve UnionFind template
Add reset() to return to starting state
Diffstat:
1 file changed, 5 insertions(+), 0 deletions(-)
diff --git a/Templates/Union_Find.cpp b/Templates/Union_Find.cpp
@@ -29,6 +29,11 @@ class UnionFind {
size[x] = 0;
}
+ void reset() {
+ memset(size.data(), 0x00, size.size() * sizeof(int));
+ iota(begin(root), end(root), 0);
+ }
+
int count() const { return cnt; }
bool connected(int x, int y) const { return find(x) == find(y); }
};