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
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <queue>

class graph
{
public:
	
	struct node
	{
		std::set<int> e;
		int color;
		
		void remove(int n)
		{
			auto it = e.find(n);
			if (it != e.end())
				e.erase(it);
		}
	};
	
	std::map<int, node> V;
	
	void Init(int n)
	{
		for (int i=1;i<=n;++i)
			V[i] = {{}, -1};
	}
	
	void insert(int a, int b)
	{
		V[a].e.insert(b);
		V[b].e.insert(a);
	}
	
	void remove(int d)
	{
		std::queue<int> toDel;
		for (auto &it:V)
			if (it.second.e.size() < d)
				toDel.push(it.first);
			
		while (!toDel.empty())
		{
			int v = toDel.front();
			toDel.pop();
			
			auto it = V.find(v);
			if (it == V.end())
				continue;
			
			for (auto n : it->second.e)
			{
				V[n].remove(v);
				if (V[n].e.size() < d)
					toDel.push(n);
			}
			
			V.erase(it);
		}
	}
	
	std::pair<int,int> Color()
	{
		int best = 0;
		int who = -1;
		for (auto &it : V)
			if (it.second.color == -1)
			{
				int count = BFS(it.first);
				if (count > best)
				{
					best = count;
					who = it.first;
				}
			}
		return {who, best};
	}
	
	int BFS(int v)
	{
		int color = v;
		std::queue<int> q;
		q.push(v);
		int num = 1;
		
		V[v].color = color;
		while (!q.empty())
		{
			v = q.front();
			q.pop();
			
			for (auto n : V[v].e)
			{
				if (V[n].color == -1)
				{
					V[n].color = color;
					q.push(n);
					num++;
				}
			}
		}
		
		return num;
	}
};

graph G;

int main(int argc, char **argv)
{	
	std::ios_base::sync_with_stdio(0);
	
	int n,m,d;
	std::cin >> n >> m >> d;
	
	G.Init(n);
	
	for (int i=0;i<m;++i)
	{
		int a,b;
		std::cin >> a >> b;
		G.insert(a,b);
	}
	
	G.remove(d);
	auto r = G.Color();
	
	if (r.first == -1)
		std::cout << "NIE";
	else
	{
		std::cout << r.second << std::endl;
		for (auto &it : G.V)
			if (it.second.color == r.first)
				std::cout << it.first << " ";
	}
	
	return 0;
}