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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <list>
#include <set>
#include <map>
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int, int> PI;
typedef vector<PI> VPI;
typedef long long LL;
typedef vector<LL> VLL;
#define FOR(x, b, e) for(int x = b; x <= (e); ++x)
#define FORD(x, b, e) for(int x = b; x >= (e); --x)
#define REP(x, n) for(int x = 0; x < (n); ++x)
#define VAR(v, n) __typeof(n) v = (n)
#define FOREACH(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(x) ((int)(x).size())
#define PB push_back
#define MP make_pair
#define ST first
#define ND second
const int INF = 1000000001;
const double EPS = 10e-9;


const int NOT_VISITED = -2;
const int CAN_NOT_BE_ADDED = -1;

template<class V, class E>
struct Graph
{
	struct Ed : E
	{
		int v;
		Ed(E d, int w) : E(d), v(w) { }
	};

	struct Vs : V, vector<Ed> { };

	vector<Vs> g;
	vector<int> qu;
	int d;

	Graph(int n, int param) : g(n), qu(n)
	{
		d = param;
		REP(x, n)
		{
			g[x].status = NOT_VISITED;
		}
	}

	void edgeD(int b, int e, E d = E())
	{
		g[b].PB(Ed(d, e));
	}

	void edgeU(int b, int e, E d = E())
	{
		Ed eg(d, e);
		eg.rev = SIZE(g[e]);
		g[b].PB(eg);
		eg.rev = SIZE(g[eg.v = b]) - 1;
		g[e].PB(eg);
	}

	void write()
	{
		REP(x, SIZE(g))
		{
			cout << x << ": ";
			FOREACH(it, g[x]) cout << it->v << " ";
			cout << endl;
		}
	}

	struct djcmp
	{
		bool operator() (const Vs* a, const Vs* b) const
		{
			return (a->left == b->left) ? a < b : a->left < b->left;
		}
	};

	void eliminate()
	{
		set<Vs*, djcmp> pool;
		REP(x, SIZE(g))
		{
			g[x].left = SIZE(g[x]);
			pool.insert(&g[x]);
		}
		while (!pool.empty())
		{
			Vs *least = *(pool.begin());
			pool.erase(pool.begin());

			if (least->left < d)
			{
				for (auto it : *least)
				{
					if (g[it.v].status == NOT_VISITED)
					{
						pool.erase(&g[it.v]);
						--g[it.v].left;
						pool.insert(&g[it.v]);
					}
				}
				least->status = CAN_NOT_BE_ADDED;
			}
			else
			{
				break;
			}
		}
	}

	vector<int> bfs(int s, int status)
	{
		int b, e;
		vector<int> res;
		g[s].status = status;
		b = e = 0;
		qu[0] = s;
		res.push_back(s);
		while (b <= e)
		{
			s = qu[b++];
			for (auto it : g[s])
			{
				if (g[it.v].status == NOT_VISITED)
				{
					g[it.v].status = status;
					qu[++e] = it.v;
					res.push_back(it.v);
				}
			}
		}
		return res;
	}

	vector<int> compute()
	{
		eliminate();

		int status = 0;
		vector<int> best;
		for (int i = 0; i < SIZE(g); ++i)
		{
			if (g[i].status == NOT_VISITED)
			{
				vector<int> list = bfs(i, status++);
				if (SIZE(list) > SIZE(best))
				{
					best = list;
				}
			}
		}
		sort(best.begin(), best.end());
		return best;
	}
};

struct Vs
{
	int left;
	int status;
};

struct Ve
{
	int rev;
};

int main()
{
	int n, m, d;
	scanf("%d%d%d", &n, &m, &d);
	Graph<Vs, Ve> g(n, d);
	REP(x, m)
	{
		int b, e;
		scanf("%d%d", &b, &e);
		g.edgeU(b - 1, e - 1);
	}

	auto res = g.compute();
	if (SIZE(res) > 0)
	{
		printf("%d\n", SIZE(res));
		for (auto it : res)
		{
			printf("%d ", it + 1);
		}
		printf("\n");
	}
	else
	{
		printf("NIE\n");
	}
	return 0;
}