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 <cstring>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

const int MAX_N = 200010;

int n, m, d;
vector<int> v[MAX_N];
int deg[MAX_N];
bool banned[MAX_N];
bool seen[MAX_N];

void dfs(int x, vector<int>& cc)
{
	seen[x] = true;
	cc.push_back(x);
	for (unsigned i = 0; i < v[x].size(); ++i)
	{
		int u = v[x][i];
		if (!banned[u] && !seen[u])
		{
			dfs(u, cc);
		}
	}
}

void solve()
{
	queue<int> q;
	memset(banned, false, sizeof(banned));
	for (int i = 1; i <= n; ++i)
	{
		deg[i] = v[i].size();
		if (deg[i] < d)
		{
			banned[i] = true;
			q.push(i);
		}
	}
	
	while (!q.empty())
	{
		int u = q.front();
		q.pop();
		for (unsigned i = 0; i < v[u].size(); ++i)
		{
			int next = v[u][i];
			--deg[next];
			if (!banned[next] && deg[next] < d)
			{
				banned[next] = true;
				q.push(next);
			}
		}
	}
	
	memset(seen, false, sizeof(seen));
	vector<vector<int> > cc;
	for (int i = 1; i <= n; ++i)
	{
		if (!banned[i] && !seen[i])
		{
			cc.push_back(vector<int>());
			dfs(i, cc.back());
		}
	}
	
	if (cc.empty())
	{
		printf("NIE\n");
	}
	else
	{
		int mx = 0;
		int mxIndex = 0;
		for (unsigned i = 0; i < cc.size(); ++i)
		{
			if (mx < cc[i].size())
			{
				mx = cc[i].size();
				mxIndex = i;
			}
		}
		sort(cc[mxIndex].begin(), cc[mxIndex].end());
		printf("%d\n", mx);
		printf("%d", cc[mxIndex][0]);
		for (unsigned i = 1; i < cc[mxIndex].size(); ++i)
		{
			printf(" %d", cc[mxIndex][i]);
		}
		printf("\n");
	}
}

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