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
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <stack>
using namespace std;

int main(void){
    //FILE *in;
    //in=fopen("mis3.in","r");
    int n,m,d,i,j,k,a,tmp1,tmp2;
    scanf("%d%d%d",&n,&m,&d);
    //fscanf(in,"%d",&n);
    //fscanf(in,"%d",&m);
    //fscanf(in,"%d",&d);
    vector<vector<int> > lista;
    vector<int> ctrl_s;
    vector<int> s;
    stack<int> stos;
    bool has_d[n];
    bool marked[n];
    lista.resize(n);
    for(i=0;i<m;i++){
        scanf("%d%d", &tmp1,&tmp2);
	//fscanf(in,"%d",&tmp1);
	//fscanf(in,"%d",&tmp2);
        lista[tmp1-1].push_back(tmp2-1);
        lista[tmp2-1].push_back(tmp1-1);
    }
    tmp1=0;
    for(a=0;a<1000;a++){
    for(i=0;i<n;i++){
      if(lista[i].size()<d){
	for(j=0;j<lista[i].size();j++){
	  for(k=0;k<lista[lista[i][j]].size();k++){
	    if(lista[lista[i][j]][k]==i)lista[lista[i][j]].erase(lista[lista[i][j]].begin()+k);
	  }
	}
	lista[i].clear();
      }
        marked[i]=false;
    }
    }
    tmp1=0;
    for(i=0;i<n;i++){
        if(!marked[i]){
            stos.push(i);
            while(!stos.empty()){
                tmp1=stos.top();
                stos.pop();
                if(!marked[tmp1]){
                    ctrl_s.push_back(tmp1);
                    marked[tmp1]=true;
                    for(j=0;j<lista[tmp1].size();++j) stos.push(lista[tmp1][j]);
                }
            }
            if(ctrl_s.size()>s.size()) s.swap(ctrl_s);
            ctrl_s.clear();
        }
    }
    if(s.size()<=1) {printf("NIE");return 0;}
    else{
        sort(s.begin(),s.end());
        printf("%d\n",s.size());
        for(i=0;i<s.size();i++) printf("%d ",s[i]+1);
        return 0;
    }
}