This documentation is automatically generated by online-judge-tools/verification-helper
#include "library/graphs/dsu.hpp"
#pragma once
struct DSU {
std::vector<int> e;
DSU() = default;
DSU(int n) { init(n); }
void init(int n) { e = std::vector<int>(n, -1); }
int get(int x) { return e[x] < 0 ? x : e[x] = get(e[x]); }
bool same_set(int a, int b) { return get(a) == get(b); }
int size(int x) { return -e[get(x)]; }
bool unite(int x, int y) {
x = get(x), y = get(y);
if (x == y) return false;
if (e[x] > e[y]) std::swap(x, y);
e[x] += e[y];
e[y] = x;
return true;
}
};
struct DSU {
std::vector<int> e;
DSU() = default;
DSU(int n) { init(n); }
void init(int n) { e = std::vector<int>(n, -1); }
int get(int x) { return e[x] < 0 ? x : e[x] = get(e[x]); }
bool same_set(int a, int b) { return get(a) == get(b); }
int size(int x) { return -e[get(x)]; }
bool unite(int x, int y) {
x = get(x), y = get(y);
if (x == y) return false;
if (e[x] > e[y]) std::swap(x, y);
e[x] += e[y];
e[y] = x;
return true;
}
};