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
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.StringTokenizer;

public class mis {

	public static void main(String[] args) throws IOException {
		
		mis solver = new mis();
		solver.init();
		solver.solve();
	}
	
	private void init() {
		
	}
	
	int N,M,D;
	
	private static class Node {
		List<Integer> edges = new LinkedList<Integer>();
		boolean visited = false;
		int D;
		
	}
	
	private void solve() throws IOException { 
		Reader in = new Reader(System.in);
		PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
		
		N = in.nextInt();
		M = in.nextInt();
		D = in.nextInt();
		
		Node[] graph = new Node[N+1];
		for (int i = 1; i <= N; i++) graph[i] = new Node();
		for (int j = 0; j < M; j++) {
			int v = in.nextInt();
			int u = in.nextInt();
			graph[v].edges.add(u);
			graph[u].edges.add(v);
		}
		
		
		LinkedList<Integer> queue = new LinkedList<Integer>();
		for (int i = 1; i <= N; i++) {
			graph[i].D = graph[i].edges.size();
			if (graph[i].D < D) {
				graph[i].visited = true;
				queue.add(i);
			}
		}
		while (!queue.isEmpty()) {
			Integer idx = queue.pollFirst();
			for (Integer e : graph[idx].edges) {
				graph[e].D--;
				if (!graph[e].visited && graph[e].D < D) {
					graph[e].visited = true;
					queue.add(e);
				}
			}
		}
		
		
		
		for (int i = 1; i <= N; i++) graph[i].visited = false;
		List<Integer> best = new LinkedList<Integer>();
		
		for (int i = 1; i <= N; i++) {
			if (!graph[i].visited && graph[i].D >= D) {
				List<Integer> curr = new LinkedList<Integer>();
				queue = new LinkedList<Integer>();
				queue.add(i);
				while (!queue.isEmpty()) {
					Integer idx = queue.pollFirst();
					if (!graph[idx].visited && graph[idx].D >= D) {
						curr.add(idx);
						graph[idx].visited = true;
						queue.addAll(graph[idx].edges);
					}
				}
				if (curr.size() > best.size()) {
					best = curr;
				}
			}
		}
		
		Collections.sort(best);
		if (best.isEmpty()) {
			out.println("NIE");
		} else {
			out.println(best.size());
			for (Integer v : best) out.print(v + " ");
			out.println();
		}
		
		out.flush();
		out.close();
	}
	
	private static class Reader {
	    BufferedReader reader;
	    StringTokenizer tokenizer;

	    /** call this method to initialize reader for InputStream */
	    Reader(InputStream input) {
	        reader = new BufferedReader(
	                     new InputStreamReader(input) );
	        tokenizer = new StringTokenizer("");
	    }

	    public void skipLine() throws IOException {
			reader.readLine();
		}

		/** get next word */
	    public String next() throws IOException {
	        while ( ! tokenizer.hasMoreTokens() ) {
	            //TODO add check for eof if necessary
	            tokenizer = new StringTokenizer(
	                   reader.readLine() );
	        }
	        return tokenizer.nextToken();
	    }

	    public int nextInt() throws IOException {
	        return Integer.parseInt( next() );
	    }
	    
	    public double nextDouble() throws IOException {
	        return Double.parseDouble( next() );
	    }
	    
	    public long nextLong() throws IOException {
	    	return Long.parseLong(next());
	    }
	}
}