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 <algorithm>
#include <set>
#include <queue>
#include <bitset>
std::set<int> v[200000];
std::bitset<200000> zlicz;
std::queue<int> DQ;
int *Q = NULL, *Q2 = NULL, K[200001], K2[200001];
int q[200000], n, m, a, b;
uint d;
int main() {
	Q=K;
	Q2=K2;
	scanf("%d%d%u", &n, &m, &d);
	for (int i = 0; i < m; i++) {
		scanf("%d%d", &a, &b);
		v[a-1].insert(b-1); // nlogn
		v[b-1].insert(a-1); // nlogn
	}
	for (int i = 0; i < n; i++) {
		q[i] = i;
		if (v[i].size() < d) {
			DQ.push(i);
		}
	}
	while(DQ.size()) {
		int i = DQ.front();
		DQ.pop();
		if (v[i].size() < d) {
			for (auto l : v[i]) {
				if (v[l].size() == d) {
					DQ.push(l);
				}
				v[l].erase(i); // also nlogn
			}
			v[i].clear();		// nlogn
		}
	}
	int max = -1, maxof;
	for (int i = 0; i < n; i++) {
		if (v[i].size() > 0) {
			int of = 1;
			int mf = 0;
			Q[0] = i;
			// Q.push(i); // zakodzic Q na tablicy
			zlicz[i] = true;
			int curwyn = 1;
			while(mf < of) {
				int c = Q[mf++];
				for (auto g : v[c]) {
					if (!zlicz[g]) {
						Q[of++] = g;
						zlicz[g] = true;
						curwyn++;
					}
				}
			}
			if (curwyn > max) {
				max = curwyn;
				maxof = of;
				std::swap(Q, Q2);
			}
		}
	}
	if (max < 0) {
		printf("NIE\n");
	} else {
		std::sort(Q2, Q2+maxof);
		printf("%d\n", max);
		int of = 0;
		while (of < maxof) {
			printf("%d ", Q2[of++]+1);
		}
		printf("\n");
	}
}