#include<iostream>
using namespace std;
int n,m,d,a,b,k=0,i=1,s;
int main()
{
cin>>n>>m>>d;
int tab[n+1][m+1];
int ta[n+1];
for(int x=0;x<n+1;x++){
ta[x]=0;
for(int y=0;y<m+1;y++)tab[x][y]=0;
}
for(int x=0;x<m;x++){
cin>>a>>b;
tab[a][tab[a][m]]=b;
tab[a][m]++;
tab[b][tab[b][m]]=a;
tab[b][m]++;
}
for(int x=1;x<=n;x++){
if(tab[x][m]!=0){
if (tab[x][m]<d){
int h=tab[x][m];
for(int y=0;y<=h;y++){
if(tab[x][y]!=0){
for(int z=0;z<tab[tab[x][y]][m];z++) if(tab[tab[x][y]][z]==x){
tab[tab[x][y]][z]=0;
tab[tab[x][y]][m]--;
}
tab[x][y]=0;
tab[x][m]--;
if(tab[x][m]==0)y=h;
}
}
x=1;
}
}
}
for(int x=1;x<=n;x++){
if(tab[x][m]>k&&tab[x][m]>=d){
s=x;
k=tab[x][m];
}
}
if (k==0)cout<<"NIE";
else {
for(int x=0;x<m;x++){
ta[s]=s;
if(tab[s][x]>0){
ta[tab[s][x]]=tab[s][x];
i++;
}
}
do{
k=0;
for(int x=1;x<=n;x++){
for(int y=0;y<m;y++)if(tab[x][y]!=ta[tab[x][y]]){
ta[tab[x][y]]=tab[x][y];
k++;
i++;
}
}
}while(k!=0);
cout<<i<<endl;
for(int x=0;x<=n;x++)if(ta[x]!=0)cout<<ta[x]<<" ";
}
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 | #include<iostream> using namespace std; int n,m,d,a,b,k=0,i=1,s; int main() { cin>>n>>m>>d; int tab[n+1][m+1]; int ta[n+1]; for(int x=0;x<n+1;x++){ ta[x]=0; for(int y=0;y<m+1;y++)tab[x][y]=0; } for(int x=0;x<m;x++){ cin>>a>>b; tab[a][tab[a][m]]=b; tab[a][m]++; tab[b][tab[b][m]]=a; tab[b][m]++; } for(int x=1;x<=n;x++){ if(tab[x][m]!=0){ if (tab[x][m]<d){ int h=tab[x][m]; for(int y=0;y<=h;y++){ if(tab[x][y]!=0){ for(int z=0;z<tab[tab[x][y]][m];z++) if(tab[tab[x][y]][z]==x){ tab[tab[x][y]][z]=0; tab[tab[x][y]][m]--; } tab[x][y]=0; tab[x][m]--; if(tab[x][m]==0)y=h; } } x=1; } } } for(int x=1;x<=n;x++){ if(tab[x][m]>k&&tab[x][m]>=d){ s=x; k=tab[x][m]; } } if (k==0)cout<<"NIE"; else { for(int x=0;x<m;x++){ ta[s]=s; if(tab[s][x]>0){ ta[tab[s][x]]=tab[s][x]; i++; } } do{ k=0; for(int x=1;x<=n;x++){ for(int y=0;y<m;y++)if(tab[x][y]!=ta[tab[x][y]]){ ta[tab[x][y]]=tab[x][y]; k++; i++; } } }while(k!=0); cout<<i<<endl; for(int x=0;x<=n;x++)if(ta[x]!=0)cout<<ta[x]<<" "; } return 0; } |
English