#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<list>
#include<stack>
#include<string>
using namespace std;
int n,m,d,a,b,licz=0,mx=0,numer,stop[200009];
set<int> secik;
vector<int> tab[200009];
bool odw[200009],odw1[200009];
void DFS0(int q){
stop[q]=0;
odw[q]=1;
odw1[q]=1;
for(int i=0; i<tab[q].size(); i++){
if(stop[tab[q][i]]>0){
stop[tab[q][i]]--;
if(stop[tab[q][i]]<d) DFS0(tab[q][i]);
}
}
};
void DFS(int q){
odw[q]=1;
licz++;
for(int i=0; i<tab[q].size(); i++){
if(odw[tab[q][i]]==0 && stop[tab[q][i]]>0) DFS(tab[q][i]);
}
};
void WYNIK(int q){
odw1[q]=1;
secik.insert(q);
for(int i=0; i<tab[q].size(); i++){
if(odw1[tab[q][i]]==0 && stop[tab[q][i]]>0) WYNIK(tab[q][i]);
}
};
main()
{
scanf("%d%d%d", &n, &m, &d);
for(int i=0; i<m; i++){
scanf("%d%d", &a, &b);
tab[a].push_back(b);
tab[b].push_back(a);
stop[a]++;
stop[b]++;
}
for(int i=1; i<=n; i++){
//cout<<i<<" "<<stop[i]<<endl;
if(stop[i]<d && stop[i]>0) DFS0(i);
}
for(int i=1; i<=n; i++){
licz=0;
//cout<<i<<" "<<odw[i]<<" "<<stop[i]<<endl;
if(odw[i]==0 && stop[i]>0) DFS(i);
if(licz>mx){
mx=licz;
numer=i;
}
}
if(numer==0) printf("NIE\n");
else{
WYNIK(numer);
printf("%d\n", mx);
for(set<int>::iterator it=secik.begin(); it!=secik.end(); ++it){
printf("%d ", *it);
}
}
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 | #include<iostream> #include<cstdio> #include<cmath> #include<algorithm> #include<vector> #include<set> #include<map> #include<list> #include<stack> #include<string> using namespace std; int n,m,d,a,b,licz=0,mx=0,numer,stop[200009]; set<int> secik; vector<int> tab[200009]; bool odw[200009],odw1[200009]; void DFS0(int q){ stop[q]=0; odw[q]=1; odw1[q]=1; for(int i=0; i<tab[q].size(); i++){ if(stop[tab[q][i]]>0){ stop[tab[q][i]]--; if(stop[tab[q][i]]<d) DFS0(tab[q][i]); } } }; void DFS(int q){ odw[q]=1; licz++; for(int i=0; i<tab[q].size(); i++){ if(odw[tab[q][i]]==0 && stop[tab[q][i]]>0) DFS(tab[q][i]); } }; void WYNIK(int q){ odw1[q]=1; secik.insert(q); for(int i=0; i<tab[q].size(); i++){ if(odw1[tab[q][i]]==0 && stop[tab[q][i]]>0) WYNIK(tab[q][i]); } }; main() { scanf("%d%d%d", &n, &m, &d); for(int i=0; i<m; i++){ scanf("%d%d", &a, &b); tab[a].push_back(b); tab[b].push_back(a); stop[a]++; stop[b]++; } for(int i=1; i<=n; i++){ //cout<<i<<" "<<stop[i]<<endl; if(stop[i]<d && stop[i]>0) DFS0(i); } for(int i=1; i<=n; i++){ licz=0; //cout<<i<<" "<<odw[i]<<" "<<stop[i]<<endl; if(odw[i]==0 && stop[i]>0) DFS(i); if(licz>mx){ mx=licz; numer=i; } } if(numer==0) printf("NIE\n"); else{ WYNIK(numer); printf("%d\n", mx); for(set<int>::iterator it=secik.begin(); it!=secik.end(); ++it){ printf("%d ", *it); } } return 0; } |
English