#include #include #include #include #include #include #include #include #include #include #include #define INF (long long)1000000000 #define MOD 1000000007 #define EPS 1e-8 #define REP(i, m) for(long long i = 0; i < m; ++i) #define FOR(i, n, m) for(long long i = n; i < m; ++i) #define ALL(v) v.begin(), v.end() #define pb push_back using namespace std; typedef long long ll; typedef pair P; typedef long double ld; class union_find { public: union_find(int n) : par_(n, -1) {} void init(int n) { par_.assign(n, -1); } int root(int x) { return par_[x] < 0 ? x : par_[x] = root(par_[x]); } bool unite(int x, int y) { x = root(x); y = root(y); if(x == y) { return false; } else { par_[x] += par_[y]; par_[y] = x; return true; } } bool same(int x, int y) { return root(x) == root(y); } int size(int x) { return -par_[root(x)]; } private: std::vector par_; }; int main() { int n,m; cin>>n>>m; union_find uf(n); REP(i,m) { int a, b; cin>>a>>b; --a; --b; if(uf.same(a,b)) continue; if(uf.size(a)>uf.size(b)) { uf.unite(a,b); } else if(uf.size(b)>uf.size(a)) { uf.unite(b,a); } else { if(uf.root(a)