#include #include #include #include #include #include #include #include using namespace std; typedef struct tree tree; struct tree { int key; int rank; struct tree *parent; }; void make_set(tree *x, int key){ x->parent = x; x->key = key; x->rank = 1; } tree *find_set(tree *x){ if(x != x->parent) x->parent = find_set(x->parent); return x->parent; } void link(tree *x, tree *y){ if( find_set(x)->rank > find_set(y)->rank || ( find_set(x)->rank == find_set(y)->rank && find_set(x)->key < find_set(y)->key) ){ find_set(x)->rank += find_set(y)->rank; y->parent = x; } else{ find_set(y)->rank += find_set(x)->rank; x->parent = y; } } void union_set(tree *x, tree *y){ link(find_set(x),find_set(y)); } int main() { int n,m; cin >> n >> m; tree *t[10001]; for(int i=0;i> a >> b; a--; b--; if(find_set(t[a]) != find_set(t[b])) union_set(t[a],t[b]); } int ans[10001]={}; for(int i=0;ikey + 1 << endl; return 0; }