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
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

vector<int> G[200001];
int color[200001]; 
int D[200001]; 
int component[200001];
bool exist[200001];
vector<int> C[200001]; 
queue<int> Q;
int n,m,d;
int ileExist, maxsize, maxcomp;

void BFS(int s, int nr)
{
	Q.push(s);
	color[s] = 0;
	C[nr].push_back(s);
	component[s] = nr;
	
	while(!Q.empty())
	{
		int x = Q.front();
		Q.pop();
		for(int i=0; i<G[x].size(); i++)
		{
			int y = G[x][i];
			if(exist[y])
			{
				if(color[y] == 0)
				{
					D[x]++;
					color[y] = 1;
					C[nr].push_back(y);
					component[y]=nr;
					Q.push(y); 	
				}
				else if(component[y] == nr)
					D[x]++;			
			}
		}
		color[x] = 2;
	}
	return;
}

void cutting()
{
	for(int i=0; i<n; i++)
	{
		if(exist[i])
		{
			if (D[i] < d)
			{
				exist[i] = false;
				ileExist--;
			}
	}
		D[i]=0;
		color[i] = 0;
		component[i] = -1;
		C[i].clear();
	}	
	return;
}

bool find_component()
{
	int numer=0;
	for(int i=0; i<n; i++)
		if(exist[i] && color[i] == 0)
		{
			BFS(i, numer);
			numer++;
		}
		
	maxsize = 1;
	maxcomp = -1;
	
	for(int i=0; i<numer; i++)
		if(C[i].size() > maxsize)
		{
			bool dok = true;
			for(int j=0; j<C[i].size(); j++)
				if(D [ C[i][j] ] < d)
					dok = false;
			if(dok)
			{
				maxsize = C[i].size();
				maxcomp = i;
			}
		}	
	if(maxcomp == -1) return false;
	else return true;	
}


int main()
{
	cin >> n >> m >> d;
	
	for(int i=0; i<=n; i++)
	{
		G[i].clear();
		C[i].clear();
		color[i] = 0;
		D[i] = 0;
		exist[i] = true;
		component[i] = -1;
	}

	int a1, a2;
	for(int i=0; i<m; i++)
	{		
		cin >> a1 >> a2;
		a1--; a2--;
		
		G[a1].push_back(a2);
		G[a2].push_back(a1);

	}
	
	ileExist = n;

	while(!find_component())
	{
		cutting();
		if(ileExist <= 0)
			break;	
	}
		
	if(ileExist>0)
	{
		cout << maxsize << endl;
		sort(C[maxcomp].begin(), C[maxcomp].end());
		for(int i=0; i<C[maxcomp].size(); i++)
			cout << C[maxcomp][i]+1 << " ";
	}
	else
		cout << "NIE";
	
	return 0;
}