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

const int MX = 200000;

int n, m, d, a, b, w[MX + 10], deg[MX + 10], num_of_nodes, mx_siz, siz, mx_id;
bool vis[MX + 10], deleted[MX + 10];

vector<int> v[MX + 10];
priority_queue<pair<int, int> > q;

int dfs(int x, int id) {
	vis[x] = true;
	w[x] = id;
	int curr_siz = 1;
	for (int i = 0; i < (int)v[x].size(); ++i) {
		if (!deleted[v[x][i]] && !vis[v[x][i]])
			curr_siz += dfs(v[x][i], id);
	}
	return curr_siz;
}

int main() {
	scanf("%d%d%d", &n, &m, &d);
	for (int i = 0; i < m; ++i) {
		scanf("%d%d", &a, &b);
		v[a].push_back(b);
		v[b].push_back(a);
		deg[a]++;
		deg[b]++;
	}

	for (int i = 1; i <= n; ++i) {
		q.push(make_pair(-deg[i], i));
	}

	while(!q.empty()) {
		pair<int, int> a = q.top();
		q.pop();

		if (deleted[a.second])
			continue;
		if (-a.first >= d)
			break;

		deleted[a.second] = true;
		for (int i = 0; i < (int)v[a.second].size(); ++i) {
			deg[v[a.second][i]]--;
			q.push(make_pair(-deg[v[a.second][i]], v[a.second][i]));
		}
	}

	for (int i = 1; i <= n; ++i) {
		if (!deleted[i] && !vis[i]) {
			siz = dfs(i, i);
			if (siz > mx_siz) {
				mx_siz = siz;
				mx_id = i;
			}
		}
	}

	if (mx_siz) {
		printf("%d\n", mx_siz);
		for (int i = 1; i <= n; ++i) {
			if (w[i] == mx_id)
				printf("%d ", i);
		}
	}
	else
		printf("NIE");
}