15 std::vector<int64_t> p;
16 std::vector<int64_t> depth;
17 std::vector<int64_t> ssize;
18 std::vector<int64_t> max_el;
19 std::vector<int64_t> min_el;
27 explicit dsu(int64_t n) {
29 for (int64_t i = 0; i < n; i++) {
36 for (int64_t i = 0; i < n; i++) {
41 for (int64_t i = 0; i < n; i++) {
56 return (p[i] =
find(p[i]));
66 void join(int64_t i, int64_t j) {
74 if (depth[x] > depth[y]) {
79 if (depth[x] == depth[y]) {
83 max_el[y] = std::max(max_el[x], max_el[y]);
84 min_el[y] = std::min(min_el[x], min_el[y]);
95 bool same(int64_t i, int64_t j) {
102 std::vector<int64_t> get(int64_t i) {
103 std::vector<int64_t> ans;
106 ans.push_back(
size(i));
disjoint set class
Definition disjoint_set.h:13
void join(int64_t i, int64_t j)
join function
Definition disjoint_set.h:66
int64_t size(int64_t i)
size function
Definition disjoint_set.h:116
bool same(int64_t i, int64_t j)
same function
Definition disjoint_set.h:95
int64_t get_min(int64_t i)
get the minimum element of the set that i exists in
Definition disjoint_set.h:132
int64_t get_max(int64_t i)
get the maximum element of the set that i exists in
Definition disjoint_set.h:124
int64_t find(int64_t i)
find function
Definition disjoint_set.h:52
dsu(int64_t n)
Construct a new dsu object.
Definition disjoint_set.h:27