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
#include <bits/stdc++.h>
#define REP(a,b) for(int a=0; a<(b); ++a)
#define FWD(a,b,c) for(int a=(b); a<(c); ++a)
#define FWDS(a,b,c,d) for(int a=(b); a<(c); a+=d)
#define BCK(a,b,c) for(int a=(b); a>(c); --a)
#define ALL(a) (a).begin(), (a).end()
#define SIZE(a) ((int)(a).size())
#define SQ(a) ((a)*(a))
#define VAR(x) #x ": " << x << " "
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll
#define gcd __gcd
#define x first
#define y second
#define st first
#define nd second
#define pb push_back

using namespace std;

template<typename T> ostream& operator<<(ostream &out, const vector<T> &v){ out << "{"; for(const T &a : v) out << a << ", "; out << "}"; return out; }
template<typename S, typename T> ostream& operator<<(ostream &out, const pair<S,T> &p){ out << "(" << p.st << ", " << p.nd << ")"; return out; }

typedef long long int64;
typedef pair<int, int> PII;
typedef pair<int64, int64> PLL;
typedef long double K;
typedef vector<int> VI;

const int dx[] = {0,0,-1,1}; //1,1,-1,1};
const int dy[] = {-1,1,0,0}; //1,-1,1,-1};

const int INF = 1e9;
const int64 MOD = SQ(1000LL * 1000 * 1000);

int n, m, d;
vector<int> E[200010];
int deg[200010];
bool vis[200010];
vector<int> S;
queue<int> Q;
vector<int> R;

void dfs(int u){
	vis[u] = 1;
	S.push_back(u);
	for(int v : E[u])
		if(!vis[v])
			dfs(v);
}

int main(){
	scanf("%d %d %d", &n, &m, &d);
	FWD(i,0,m){
		int a, b;
		scanf("%d %d", &a, &b);
		E[a].push_back(b);
		E[b].push_back(a);
	}
	FWD(i,1,n+1){
		deg[i] = SIZE(E[i]);
		if(deg[i] < d){
			vis[i] = 1;
			Q.push(i);
		}
	}
	while(!Q.empty()){
		int u = Q.front();
		Q.pop();
		for(int v : E[u]){
			--deg[v];
			if(deg[v] < d && !vis[v]){
				vis[v] = 1;
				Q.push(v);
			}
		}
	}
	FWD(i,1,n+1){
		S.clear();
		if(!vis[i]) dfs(i);
		if(SIZE(S) > SIZE(R)) R = S;
	}
	if(R.empty()){
		printf("NIE\n");
		return 0;
	}
	printf("%d\n", SIZE(R));
	for(int x : R) printf("%d ", x);
	printf("\n");
	return 0;
}