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
#include <iostream>
#include <cstdio>
#include <ctime>
#include <algorithm>
#include <vector>
using namespace std;

const int N = 200007;

int n, m, d;
int st[N];
vector <int> G[N];
int wyn = 0;
int gg = -1;
int odw[N];
int odw2[N];
int ileg;
vector <int> resv;

void DFS(int v) {
	ileg++;
	odw[v] = 1;
	for(int j = 0; j < G[v].size(); ++j) if(!odw[G[v][j]]) DFS(G[v][j]);
}	

void DFS2(int v) {
	odw2[v] = 1;
	resv.push_back(v);
	for(int j = 0; j < G[v].size(); ++j) if(!odw2[G[v][j]]) DFS2(G[v][j]);
}

int main() {
	ios_base::sync_with_stdio(0);
	cin >> n >> m >> d;
	for(int i = 0; i < m; ++i) {
		int a, b;
		cin >> a >> b;
		G[a].push_back(b);
		G[b].push_back(a);
		st[a]++;
		st[b]++;
	}

	vector <int> q;
	for(int i = 1; i <= n; ++i) if(st[i] < d) q.push_back(i);
	for(int it = 0; it < q.size(); ++it) {
		int u = q[it];
		st[u] = 0;
		for(int j = 0; j < G[u].size(); ++j) {
			if(st[G[u][j]] == d) q.push_back(G[u][j]);
			st[G[u][j]]--;
		}
	}

	for(int i = 1; i <= n; ++i) if(st[i] <= 0) odw[i] = odw2[i] = 1;
	//cout << "dziala\n";
	for(int i = 1; i <= n; ++i) {
		if(!odw[i]) {
			ileg = 0;
			DFS(i);
			if(ileg > wyn) {
				wyn = ileg;
				gg = i;
			}
		}
	}

	if(wyn <= 0) cout << "NIE\n";
	else {
		cout << wyn << '\n';
		DFS2(gg);
		sort(resv.begin(), resv.end());
		for(int i = 0; i < resv.size(); ++i) cout << resv[i] << ' ';
	}

	//system("pause");
	return 0;
}