#include #include "bits/stdc++.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include typedef long long ll; #define INF (1e9+1) #define rep(i,n) for(ll i=0;i<(ll)(n);i++) using namespace std; typedef pair P; int boss[10001]; int team_rank[10001]; int n, m; void init(int v) { for (int i = 1; i <= v; i++) { boss[i] = i; team_rank[i] = 1; } } int find(int x) { if (boss[x] == x) { return x; } else { return boss[x] = find(boss[x]); } } bool same(int a, int b) { return find(a) == find(b); } void unite(int a, int b) { int x = find(a); int y = find(b); if (x == y) return; if (team_rank[x] < team_rank[y]) { for (int i = 1; i <= n; i++) { if (same(i, x) && i !=x) { boss[i] = y; } } boss[x] = y; team_rank[y] +=team_rank[x]; } else if (team_rank[x] > team_rank[y]) { for (int i = 1; i <= n; i++) { if (same(i, y) && i !=y) { boss[i] = x; } } boss[y] = x; team_rank[x] +=team_rank[y]; } else { if (x < y) { for (int i = 1; i <= n; i++) { if (same(i, y) && i !=y) { boss[i] = x; } } boss[y] = x; team_rank[x] +=team_rank[y]; } else { for (int i = 1; i <= n; i++) { if (same(i, x) && i !=x) { boss[i] = y; } } boss[x] = y; team_rank[y] +=team_rank[x]; } } } int main() { cin >> n >> m; init(n); int a, b; for (int i = 0; i < m; i++) { cin >> a >> b; /* cout << "a" << find(a) << " " << "b" << find(b) << endl;*/ unite(a, b); /* cout << "a" << a << " " << "b" << b << endl; */ /* for (int i = 1; i <= n; i++) { cout << "boss" << boss[i] << " " << "teamrank" << team_rank[i] << endl; } cout << endl;*/ } for (int i = 1; i <= n; i++) { cout <