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
#include <cstdio>
#include <cstdint>
#include <list>
#include <stack>
#include <utility>
using namespace std;

typedef pair<uint32_t, uint32_t> pp_t;

const static uint32_t MAX_N = 200000;

uint32_t deg[MAX_N + 1];
list<uint32_t> E[MAX_N + 1];
bool visited[MAX_N + 1];
stack<uint32_t> S;
list<uint32_t> G, maxG;

int main() {
	uint32_t n, m, d, i, a, b;
	scanf("%lu %lu %lu", &n, &m, &d);
	for (i = 0; i < m; ++i) {
		scanf("%lu %lu", &a, &b);
		++deg[a];
		++deg[b];
		E[a].push_back(b);
		E[b].push_back(a);
	}
	for (i = 1; i <= n; ++i)
		if (deg[i] < d)
			S.push(i);

	while (!S.empty()) {
		const uint32_t v = S.top(); S.pop();
		// usuwamy krawędzie sąsiadów
		for (const uint32_t w: E[v])
			if (deg[w] >= d)
				if (--deg[w] < d)
					S.push(w);
	}

	uint32_t maxSize = 0;
	// iterujemy po niewykreślonych
	for (i = 1; i <= n; ++i) {
		if (deg[i] < d || visited[i])
			continue;

		S.push(i);
		visited[i] = true;
		G.push_back(i);
		
		while(!S.empty()) {
			const uint32_t v = S.top(); S.pop();
			for(const uint32_t w : E[v]) {
				if (!visited[w] && deg[w] >= d) {
					S.push(w);
					visited[w] = true;
					G.push_back(w);
				}
			}
		}
		if (G.size() > maxSize) {
			maxSize = G.size();
			maxG.assign(G.begin(), G.end());
		}
		G.clear();
	}

	if (maxSize) {
		maxG.sort();
		printf("%lu\n", maxSize);
		for (const uint32_t v: maxG)
			printf("%lu ", v);
	} else
		printf("NIE");

	return 0;
}