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
79
80
81
82
83
84
85
86
87
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <utility>
#include <queue>

using namespace std;

typedef long long i64;

int n,m,d;

const int MAX = 200010;
set<int> p[MAX];
int wuzzhere[MAX];
struct C { int c; };

bool operator<(const C& a, const C& b) {
	return p[a.c].size()<p[b.c].size();
}

set<C> q;

int comp;
int comps[MAX];
int mymax;
int which_max;
void dfs(int i) {
	if (wuzzhere[i]) return;
	wuzzhere[i]=comp;
	comps[comp]++;
	if (comps[comp]>mymax) {
		which_max = comp;
		mymax = comps[comp];
	}
	for (auto e : p[i]) {
		dfs(e);
	}
}
void root_dfs() {
	for (int i=1; i<=n; i++) {
		comp=i;
		dfs(i);
	}
}

int main() {
	std::ios::sync_with_stdio(false);
	cin>>n>>m>>d;
	int i;
	for (i=0; i<m; i++) {
		int a,b;
		cin>>a>>b;
		p[a].insert(b);
		p[b].insert(a);
	}

	for (i=1; i<=n; i++) {
		C c; c.c=i;
		q.insert(c);
	}

	while (!q.empty()) {
		C c = *(q.begin());
		if (p[c.c].size()>=d) break;
		q.erase(q.begin());
		for (auto e : p[c.c]) {
			C ee; ee.c=e;
			q.erase(ee);
			p[e].erase(c.c);
			q.insert(ee);	
		}
		p[c.c].clear();
	}
	if (q.empty() || p[(*(q.begin())).c].size()==0) {
		cout<<"NIE"<<endl;
		return 0;
	}
	root_dfs();
	cout<<mymax<<endl;
	for (i=1; i<=n; i++) {
		if (wuzzhere[i]==which_max) cout<<i<<" ";
	}
	cout<<endl;
	return 0;
}