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
142
143
144
145
146
147
148
#include <iostream>
#include <vector>
#include <stack>
#include <algorithm>


int main(void)
{
	long n,m,d;

	std::cin >> n >> m >> d;

	std::vector< std::vector <long> > web;
	std::vector<int> state;

	web.resize(n+1);
	state.assign(n+1, 0);

	long a,b;

	for (long i=0; i<m; i++)
	{
		std::cin >> a >> b;
		web[a].push_back(b);
		web[b].push_back(a);
	}

	
	std::vector< std::vector <long> > wellWeb;
	std::stack< long > stack;
	std::vector< long > subWeb;

	long subWebState = 1;

	for (long i=1; i<=n; i++)
	{
		if ( state[i] == 0 )
		{
			if ( web[i].size() >= d )
			{
				if (!subWeb.empty()) {
					wellWeb.push_back(subWeb);
				}
				subWeb.clear();
				subWebState += 1;
				subWeb.push_back(i);
				for(int j=0; j<web[i].size(); j++)
				{
					if( state[ web[i][j] ] == 0 ) {
						stack.push(web[i][j]);
					}
				}
				state[i] = subWebState;
			}
			else
			{
				state[i] = 1;
			}

			while(!stack.empty()) 
			{
				long x = stack.top();
				stack.pop();
				if ( state[x] == 0 )
				{
					 if ( web[x].size() >= d )
					 {
						state[x] = subWebState;
						subWeb.push_back(x);
						
						for(int j=0; j<web[x].size(); j++)
						{
							if( state[ web[x][j] ] == 0 ) {
								stack.push(web[x][j]);
							}
						}
					 }
					 else
					 {
						 state[x] = 1;
					 }
				}
			}
		}
	}
	if (!subWeb.empty()) 
	{
		wellWeb.push_back(subWeb);
	}

	//for (int i=0; i < wellWeb.size(); i++)
	//{
	//	for (int j=0; j < wellWeb[i].size(); j++)
	//	{
	//		if ( state[ wellWeb[i][j] ] == 1 )
	//		{

	//		}
	//	}
	//}











	if ( wellWeb.empty() )
	{
		std::cout << "NIE" << std::endl;
	}
	else 
	{
		int maxSize = 0;
		int iWellWeb = 0;

		for(int i=0; i < wellWeb.size(); i++)
		{
			if (wellWeb[i].size() > maxSize && wellWeb[i].size() >= d) 
			{
				maxSize = wellWeb[i].size() ;
				iWellWeb = i;
			}
		}

		if (maxSize > 0 ) 
		{
			std::sort(wellWeb[iWellWeb].begin(), wellWeb[iWellWeb].end());

			for(int i=0; i<wellWeb[iWellWeb].size(); i++)
			{
				std::cout << wellWeb[iWellWeb][i] << " ";
			}
			std::cout << std::endl;
		}
		else {
			std::cout << "NIE" << std::endl;
		}
		
	}


	return 0;
}