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
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <set>
using namespace std;
typedef vector<int> VI;
typedef long long LL;
#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 ALL(c) (c).begin(), (c).end()
#define SIZE(x) ((int)(x).size())
#define FOREACH(i, c) for (VAR(i, (c).begin()); i != (c).end(); ++i)
#define PB push_back
#define ST first
#define ND second

int n, m, d;

int heapIdx[200001];

struct City {
	int nr;
	int sss;
	set<City*> roads;
	City() : nr(-1), sss(-1) {}
};

City* cities[200001];

void heap_down(int n, int i) {
	int left = i * 2, right = i * 2 + 1;
	int smallest = i;
	if (left <= n && cities[left]->roads.size() < cities[smallest]->roads.size()) {
		smallest = left;
	}
	if (right <= n && cities[right]->roads.size() < cities[smallest]->roads.size()) {
		smallest = right;
	}
	if (i != smallest) {
		City* tmp = cities[i];
		cities[i] = cities[smallest];
		cities[smallest] = tmp;

		heapIdx[cities[i]->nr] = i;
		heapIdx[cities[smallest]->nr] = smallest;

		heap_down(n, smallest);
	}
}

void heap_up(int n, int i) {
	int parent = i / 2;
	if (parent > 0 && cities[parent]->roads.size() > cities[i]->roads.size()) {
		City* tmp = cities[i];
		cities[i] = cities[parent];
		cities[parent] = tmp;

		heapIdx[cities[i]->nr] = i;
		heapIdx[cities[parent]->nr] = parent;

		heap_up(n, parent);
	}
}

void heap_pop(int n) {
	heapIdx[cities[1]->nr] = -1;

	cities[1] = cities[n];
	heapIdx[cities[1]->nr] = 1;

	heap_down(n - 1, 1);
}

void build_heap(int n) {
	FORD(i, n, 1) heap_down(n, i);
}

int dfs(int i, int sss) {
	City* c = cities[i];
	if (c->sss != -1) return 0;
	c->sss = sss;
	int sum = 1;
	FOREACH (r, c->roads) sum += dfs(heapIdx[(*r)->nr], sss);
	return sum;
}

int main() {
	int N;
	scanf("%d %d %d", &n, &m, &d);
	N = n;
	REP (i, n + 1) {
		cities[i] = new City;
		cities[i]->nr = i;
		heapIdx[i] = i;
	}
	int from, to;
	REP (i, m) {
		scanf("%d %d", &from, &to);
		cities[from]->roads.insert(cities[to]);
		cities[to]->roads.insert(cities[from]);
	}
	build_heap(n);
	while (n > 0 && cities[1]->roads.size() < d) {
		City* top = cities[1];
		heap_pop(n--);
		FOREACH (i, top->roads) {
			int DEBUG = (*i)->roads.erase(top);
			heap_up(n, heapIdx[(*i)->nr]);
		}
		delete top;
	}
	if (n == 0) printf("NIE\n");
	else {
		int max = 0;
		int sss = -1;
		FOR(i, 1, n) {
			int tmp = dfs(i, i);
			if (tmp > max) {
				sss = i;
				max = tmp;
			}
		}
		printf("%d\n", max);
		FOR(i, 1, N) {
			if (heapIdx[i] != -1 && cities[heapIdx[i]]->sss == sss) {
				printf("%d ", cities[heapIdx[i]]->nr);
			}
		}
		printf("\n");
	}
	FOR(i, 1, n) delete cities[i];
	return 0;
}