1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| #include <bits/stdc++.h> #define ll long long #define ld long double #define N 10005 #define FOR(i,n) for(int i=0;i<n;i++) #define pii pair<int,int> using namespace std; int n,m,full[N];
set<int> s[N];
int main(){ cin>>n>>m; fill(full,full+n+1,10); for(int i=1;i<=n;i++)s[i].insert(i); while(m--){ int a,b;cin>>a>>b; if(full[b]>full[a])swap(a,b); full[a] += full[b]; full[b] = 0; for(auto p:s[b])s[a].insert(p); s[b].clear(); } int ans = max_element(full,full+n+1)-full; cout<<ans<<endl; for(auto p:s[ans])cout<<p<<" "; cout<<endl; }
|