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
/*
	Potyczki Algorytmiczne 2015
	Michal Ganczorz
*/
#include <iostream>
#include <string>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <algorithm>

#define ll long long

using namespace std;

// ll tab[1000042];

bool del[200042];
bool visited[200042];
bool visited2[200042];
int deg[200042];
vector<int> graph1[200042];
vector<int> graph2[200042];
vector<int> res;

int dfs(int v)
{
	int sm = 0;
	visited[v] = 1;
	for(int i=0; i<graph2[v].size(); ++i)
		if(!visited[graph2[v][i]])
			sm += dfs(graph2[v][i]);
	return sm + 1;
}

void dfs_print(int v)
{
	int sm = 0;
	visited2[v] = 1;
	res.push_back(v);
	for(int i=0; i<graph2[v].size(); ++i)
		if(!visited2[graph2[v][i]])
			dfs_print(graph2[v][i]);
}

struct cmp
{
    bool operator() (const int &a, const int &b)
    {
        if (deg[a] < deg[b]) return true;
        if (deg[a] > deg[b]) return false;
        return a<b;
    }
};

int main()
{
	cin.tie(NULL);
  	std::ios::sync_with_stdio(false);

  	int n,m,d;
  	cin>>n>>m>>d;

  	for(int i=0; i<m; ++i)
  	{
  		int a,b;
  		cin>>a>>b;
  		if(a != b)
  		{
  			graph1[a].push_back(b);
  			graph1[b].push_back(a);
  		}
  	}

  	set<int, cmp> mm;

  	for(int i=1; i<=n; ++i)
  	{
  		deg[i] = graph1[i].size();
  		mm.insert(i);
  	}

  	while(mm.size() != 0)
  	{
  		int vv = *(mm.begin());
  		if(deg[vv] < d)
  		{
  			del[vv] = 1;
  			deg[vv] = 0;
  			mm.erase(mm.begin());
  			for(int i=0; i<graph1[vv].size(); ++i)
  			{
  				if(!del[graph1[vv][i]])
  				{
	  				mm.erase(mm.find(graph1[vv][i]));
	  				deg[graph1[vv][i]]--;
	  				mm.insert(graph1[vv][i]);
	  			}
  			}
  		}
  		else
  			break;
  	}

  	for(int i=1; i<=n; ++i)
  		for(int j=0; j<graph1[i].size() && !del[i]; ++j)
  			if(!del[graph1[i][j]])
  				graph2[i].push_back(graph1[i][j]);

  	int mx_size = 0;
  	int mx_ind = 0;
  	for(int i=1; i<=n; ++i)
  		if(!visited[i])
  		{
  			int k = dfs(i);
  			if(mx_size < k)
  			{
  				mx_size = k;
  				mx_ind = i;
  			}
  		}

  	if(mx_size < d)
  		cout<<"NIE\n";
  	else
  	{
  		cout<<mx_size<<"\n";
  		res.clear();
  		dfs_print(mx_ind);
  		sort(res.begin(), res.end());
  		for(int i=0; i<res.size(); ++i)
  			cout<<res[i]<<" ";
  		cout<<"\n";
  	}

	return 0;
}