#include #include using namespace std; class UnionFind{ public: UnionFind(){ UnionFind(0); } UnionFind(int N){ par.resize(N); rnk.resize(N); for(int i=0;i par, rnk; }; int main(){ int N; cin >> N; UnionFind uf = UnionFind(N); int M; cin >> M; int A,B; for(int i=0;i> A >> B; A--; B--; if(uf.same(A,B)) continue; uf.unite(A,B); } for(int i=0;i