1 #ifndef dsa_DisjointSet_H__
2 #define dsa_DisjointSet_H__
28 std::vector<size_t> father_;
29 std::vector<size_t> depth_;
31 size_t root_(
size_t now) {
32 if (father_[now] == now)
return now;
33 return (father_[now] = root_(father_[now]));
36 size_t merge_(
size_t a,
size_t b) {
40 if (depth_[a] > depth_[b]) {
46 if (depth_[a] == depth_[b]) depth_[b]++;
74 n_(dsj.n_), father_(dsj.father_), depth_(dsj.depth_) {
85 size_t root(
size_t a)
const {
111 for (
size_t i = 0; i < n; i++) {
135 #endif // dsa_DisjointSet_H__
DisjointSet(DisjointSet const &dsj)
constructor
size_t merge(size_t a, size_t b)
合併
size_t root(size_t a) const
回傳指定的number所在的 集合的編號
DisjointSet(size_t n)
constructor
size_t size() const
回傳總element數