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
//
// CZAS NA INBE 
// 	          - OSTATNI PLOMIEN EUROPY
//
// https://www.youtube.com/watch?v=oNYiv8UfAb0&list=PLZqKHKLMlC58OHkkiSWqOnAp1ZHJIMKQV

#include <cstdio>
#include <vector>
#include <queue>
using namespace std;
struct Node {
	vector<int> nbs;
	int c;
	int burn;
};

Node nodes[200001];

int main() {
	int n, m, d;
	scanf("%d%d%d",&n,&m,&d);
	for (int i = 0; i < m; ++i) {
		int a, b;
		scanf("%d%d",&a,&b);
		nodes[a].nbs.push_back(b);
		nodes[b].nbs.push_back(a);
	}

	queue<int> toBurn;

	for (int i = 1; i <= n; ++i) {
		if (nodes[i].nbs.size() < d) {
			toBurn.push(i);
		}
	}


	while (!toBurn.empty()) {
		int v = toBurn.front();
		toBurn.pop();
		if (nodes[v].burn) {
			continue;
		}

		nodes[v].burn = 1;
		for (int i = 0; i < nodes[v].nbs.size(); ++i) {
			Node& nb = nodes[nodes[v].nbs[i]];
			if (nb.nbs.size() >= d) {
				for (int j = 0; j < nb.nbs.size(); ++j) {
					if (nb.nbs[j] == v) {
						nb.nbs[j] = nb.nbs[nb.nbs.size() - 1];
						nb.nbs.pop_back();
						if (nb.nbs.size() < d) {
							toBurn.push(nodes[v].nbs[i]);
						}
						break;
					}
				}
			}
		}
	}

	int best = 0;
	int bestcnt = 0;

	for (int i = 1; i <= n; ++i) {
		if (nodes[i].c == 0 && !nodes[i].burn) {
			int cnt = 0;
			queue<int> q;
			q.push(i);
			while (!q.empty()) {
				int v = q.front();
				q.pop();
				if (nodes[v].c == i) {
					continue;
				}
				nodes[v].c = i;
				cnt++;
				for (int j = 0; j < nodes[v].nbs.size(); ++j) {
					Node& nb = nodes[nodes[v].nbs[j]];
					if (!nb.burn) {
						q.push(nodes[v].nbs[j]);
					}
				}
			}
			if (cnt > bestcnt) {
				bestcnt = cnt;
				best = i;
			}
		}
	}

	if (bestcnt > 0) {
		printf("%d\n", bestcnt);
		for (int i = 1; i <= n; ++i) {
			if (nodes[i].c == best) {
				printf("%d ", i);
			}
		}
	} else {
		printf("NIE");
	}

	return 0;
}