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
#include <cstdio>
#include <list>
#include <map>
#include <set>

using namespace std;

int n, m, d;
int st[200001];;
set<int> pol[200001];
list <int> ud;	// under 'd', mniej niz d-polaczen
int on_ud[200001];	// on ud list, do not push again

int bfs(int v, int & cur, list<int>&c)
{
	cur = 0;
	c.clear();
	cur++;
	st[v]=0;
	c.push_back(v);
	list<int>::iterator it = c.begin();
	// c - list w spojnej skladowej
	for (; it  != c.end(); ++it)
	{
		for (set<int>::iterator iter = pol[*it].begin();
			iter != pol[*it].end(); ++iter)
		{
			if (st[*iter]==0)	// juz jest na liscie
				continue;
			pol[*iter].erase(*it);
			c.push_back(*iter);
			st[*iter] = 0;	// jest na liscie
			cur++;
		}
	}
	return 0;
}

int main()
{
	scanf("%d %d %d", &n, &m, &d);
	int b,e;
	for (int i =0 ; i < m; i++)
	{
		scanf("%d %d", &b, &e);	
		st[b]++;
		st[e]++;
		pol[b].insert(e);
		pol[e].insert(b);
	}
	for (int i = 1; i <= n; i++)
	{
		if (st[i] < d)
		{
			st[i] = 0;
			on_ud[i] = 1;
			for (set<int>::iterator it=pol[i].begin();it != pol[i].end(); ++it)
			{
				st[*it]--;
				pol[*it].erase(i);
				if (st[*it] < d)	
				{
					ud.push_back(*it);	
					on_ud[*it] = 1;
				}
			}
		}
	}
	
	for (list<int>::iterator it = ud.begin(); it != ud.end(); ++it)
	{
		for (set<int>::iterator its=pol[*it].begin();its != pol[*it].end(); ++its)
		{
			st[*its]--;
			pol[*its].erase(*it);
			if (st[*its] < d && ! on_ud[*its])	
			{
				ud.push_back(*its);	
				on_ud[*its] = 1;
			}
		}
	}
	// zostalu tylko st[i] >= d
	list<int> c, m;
	int cur=0, max = 0;	// curr=c.size(); max=m.size()
	for (int i = 1; i <=n ; i++)
	{
		if (st[i] >= d)
		{
			bfs(i, cur, c);
			if (cur > max)
			{
				max = cur;
				m = c;
			}
		}
	}
	if (max < d)
	{
		printf("NIE");
		return 0;
	}
	printf("%d\n", max);		
	m.sort();
	for (list<int>::iterator it=m.begin();it != m.end(); ++it)
	{
		printf("%d ", *it);
	}
	return 0;
}