#include "graph.hpp" #include class ClusterTree { private: std::vector p; std::vector o; public: ClusterTree(unsigned n) : p(n, -1), o(n, 1) {} unsigned findroot(unsigned i) { if (p[i] < 0) return i; else return p[i] = this->findroot(p[i]); } void join(unsigned i, unsigned j) { if (o[i] < o[j]) { p[i] = j; o[j] += o[i]; } else { p[j] = i; o[i] += o[j]; } } void add_bond(const graph::edge& b) { unsigned i = this->findroot(b.v[0]); unsigned j = this->findroot(b.v[1]); if (i != j) { this->join(i, j); } } bool same_component(unsigned v0, unsigned v1) { unsigned i = this->findroot(v0); unsigned j = this->findroot(v1); return i == j; } };