38#include <gtest/gtest.h>
61 vector<size_t> parent;
65 explicit RefDsu(
size_t n) : parent(n), sz(n, 1), blocks(n)
67 for (
size_t i = 0; i < n; ++i)
73 if (n <= parent.size())
76 const size_t old = parent.
size();
79 for (
size_t i =
old; i < n; ++i)
86 while (x != parent[x])
88 parent[x] = parent[parent[x]];
99 void unite(
size_t a,
size_t b)
147 const size_t before =
rel.get_num_blocks();
172 FixedRelationInspector
rel(3);
180 FixedRelationInspector
rel(3);
188 constexpr size_t n = 50;
193 std::uniform_int_distribution<size_t> pick(0, n - 1);
197 const size_t a = pick(
rng);
198 const size_t b = pick(
rng);
245 std::uniform_int_distribution<size_t> pick(0, 200);
249 const size_t a = pick(
rng);
250 const size_t b = pick(
rng);
252 ref.ensure(std::max(a, b) + 1);
301 rel.join(std::string(
"a"), std::string(
"b"));
302 EXPECT_TRUE(
rel.are_connected(std::string(
"a"), std::string(
"b")));
size_t size() const noexcept
Count the number of elements of the list.
Binary relation between a set of integers.
Fixed_Relation(const size_t n=0)
Initialize an empty binary relation of integers between 0 and n - 1.
virtual size_t root(size_t i)
size_t depth(size_t i) const
Binary relation between a set of items.
Binary relation between a set of integers.
Itor find(const Itor &beg, const Itor &end, const T &value)
Find the first element equal to a value.
DynList< T > maps(const C &c, Op op)
Classic map operation.
Union-Find (Disjoint Set Union) data structure.