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 <queue>
#include <algorithm>
using namespace std;

bool odw[1000010];
vector<int> G[1000010];
vector<int> asdf;
int kr[1000010];

int dfs(int k) {
	asdf.push_back(k);
	odw[k] = true;
	int w = 0;
	for(int i = 0; i < G[k].size(); i++)
		if(!odw[G[k][i]])
			w += dfs(G[k][i]);
	return w+1;		
}

int main() {
	int n, m, d;
	scanf("%d%d%d", &n, &m, &d);
	
	for(int i = 0; i < m; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		kr[a]++;
		kr[b]++;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	
	queue<int> q;
	for(int i = 1; i <= n; i++)
		if(kr[i] < d) {
			q.push(i);
			odw[i] = true;
		}
			
	while(!q.empty()) {
		int k = q.front();
		
		for(int i = 0; i < G[k].size(); i++) 
			if(!odw[ G[k][i] ]) {
				kr[ G[k][i] ]--;
				if(kr[ G[k][i] ] < d) {
					q.push(G[k][i]);
					odw[ G[k][i] ] = true;
				}					
			}
		q.pop();
	}		
	
	int w = 0, in = 0;
	for(int i = 1; i <= n; i++)
		if(!odw[i]) {
			int _i = asdf.size();
			int _d = dfs(i);
			if(_d > w) {
				w = _d;
				in = _i;	
			}
		}
		
	if(w == 0)
		printf("NIE");
	else {
		sort(asdf.begin() + in, asdf.begin() + (in + w));
		printf("%d\n", w);
		for(int i = in; i < in+w; i++)
			printf("%d ", asdf[i]);
	}
	
	return 0;
}