#include<bits/stdc++.h> using namespace std; int n,m,d; vector<int>st; vector<bool>bylo; vector< vector<int> >g; void wczytaj(){ scanf("%d%d%d",&n,&m,&d); st.resize(n+1); g.resize(n+1); bylo.resize(n+1); int a,b; for(int i=0;i<m;i++){ scanf("%d%d",&a,&b); g[a].push_back(b); g[b].push_back(a); st[a]++; st[b]++; } } void czysc(){ queue<int>q; for(int i=1;i<=n;i++) if(st[i]<d){ st[i]=-1; q.push(i); } int x; while(!q.empty()){ x=q.front(); q.pop(); if(bylo[x])continue; bylo[x]=true; for(int i=0;i<g[x].size();i++) if(st[g[x][i]]>0){ st[g[x][i]]--; if(st[g[x][i]]<d){ st[g[x][i]]=-1; q.push(g[x][i]); } } } } vector<int>kto,odp; void dfs(int x){ kto.push_back(x); bylo[x]=true; for(int i=0;i<g[x].size();i++) if(!bylo[g[x][i]] && st[g[x][i]]>=d) dfs(g[x][i]); } int main(){ wczytaj(); czysc(); bylo.resize(0); bylo.resize(n+1); for(int i=1;i<=n;i++) if(!bylo[i] && st[i]>=d){ kto.resize(0); dfs(i); if(odp.size()<kto.size()) odp=kto; } if(odp.size()==0){ puts("NIE"); return 0; } sort(odp.begin(),odp.end()); printf("%lu\n",odp.size()); for(int i=0;i<odp.size();i++) printf("%d ",odp[i]); return 0; }
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | #include<bits/stdc++.h> using namespace std; int n,m,d; vector<int>st; vector<bool>bylo; vector< vector<int> >g; void wczytaj(){ scanf("%d%d%d",&n,&m,&d); st.resize(n+1); g.resize(n+1); bylo.resize(n+1); int a,b; for(int i=0;i<m;i++){ scanf("%d%d",&a,&b); g[a].push_back(b); g[b].push_back(a); st[a]++; st[b]++; } } void czysc(){ queue<int>q; for(int i=1;i<=n;i++) if(st[i]<d){ st[i]=-1; q.push(i); } int x; while(!q.empty()){ x=q.front(); q.pop(); if(bylo[x])continue; bylo[x]=true; for(int i=0;i<g[x].size();i++) if(st[g[x][i]]>0){ st[g[x][i]]--; if(st[g[x][i]]<d){ st[g[x][i]]=-1; q.push(g[x][i]); } } } } vector<int>kto,odp; void dfs(int x){ kto.push_back(x); bylo[x]=true; for(int i=0;i<g[x].size();i++) if(!bylo[g[x][i]] && st[g[x][i]]>=d) dfs(g[x][i]); } int main(){ wczytaj(); czysc(); bylo.resize(0); bylo.resize(n+1); for(int i=1;i<=n;i++) if(!bylo[i] && st[i]>=d){ kto.resize(0); dfs(i); if(odp.size()<kto.size()) odp=kto; } if(odp.size()==0){ puts("NIE"); return 0; } sort(odp.begin(),odp.end()); printf("%lu\n",odp.size()); for(int i=0;i<odp.size();i++) printf("%d ",odp[i]); return 0; } |