#include #include using namespace std; class UnionFind { vector par; public: explicit UnionFind(int n) : par(n, -1) {} int root(int a) { if(par[a] < 0) { return a; } return par[a] = root(par[a]); } int size(int a) { return -par[root(a)]; } void unite(int a, int b) { a = root(a); b = root(b); if(a == b) { return; } int na = size(a), nb = size(b); if(na < nb) { swap(a, b); } if(na == nb && a > b) { swap(a, b); } par[a] += par[b]; par[b] = a; } }; int main(void) { int N, M; scanf("%d%d", &N, &M); UnionFind uf(N+1); for(int i=0; i