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

const int MAXN = 200*1000 + 9;

vector<int> g[MAXN];
int kolor[MAXN];

int KOLOR = 1;
int dfs(int x){
	if(kolor[x]) return 0;
	kolor[x] = KOLOR;
	int s = 1;
	for(int i = 0; i < g[x].size(); ++i)
		s += dfs(g[x][i]);
	return s;
}

int main(){
	ios_base::sync_with_stdio(0);
	int n, m, d;
	cin >> n >> m >> d;
	for(int i = 0; i < m; ++i){
		int a, b;
		cin >> a >> b;
		a--; 
		b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	
	queue<int> q;
	vector<int> st(n);
	for(int x = 0; x < n; ++x){
		st[x] = g[x].size();
		if(st[x] < d) q.push(x);
	}
	
	while(!q.empty()){
		int x = q.front(); q.pop();
		for(int i = 0; i < g[x].size(); ++i){
			int y = g[x][i];
			if(st[y] == d) q.push(y);
			st[y]--;
		}
	}
	
	for(int x = 0; x < n; ++x){
		if(st[x] < d) g[x].clear();
		for(int i = 0; i < g[x].size();){
			int y = g[x][i];
			if(st[y] < d){
				swap(g[x][i], g[x].back());
				g[x].pop_back();
			}
			else i++;
		}
	}
	
	int najile = 0, najkolor = 0;
	for(int x = 0; x < n; ++x){
		KOLOR = x+5;
		int ile = dfs(x);
		if(ile > najile){
			najile = ile;
			najkolor = KOLOR;
		}
	}
	
	if(najile > d){
		cout << najile << "\n";
		for(int x = 0; x < n; ++x)
			if(kolor[x] == najkolor) cout << x+1 << " ";
	}
	else cout << "NIE\n";
}