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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Collections;
import java.util.Comparator;
import java.util.Vector;

class data {
	int id;
	boolean removed;
	boolean calculated;
	boolean printed;

	Vector<Integer> roads;
	int count;

	@Override
	public String toString() {
		String a = id + "; rem:" + removed + "; calc:" + calculated + "; print:" + printed+ "; count:" + count + "; ";
		for (int i = 0; i < roads.size(); i++)
			a += roads.get(i) + ", ";
		return a;
	}
}

public class mis {

	data[] tu;
	int d;

	private static int skipWhitespace(final InputStream in) throws IOException {
		int val = -1;
		while ((val = in.read()) != -1) {
			if (!Character.isWhitespace((char) val))
				break;
		}

		return val;
	}

	private static int readInt(final InputStream in) {
		final StringBuilder b = new StringBuilder();
		try {
			int val = skipWhitespace(in);
			b.append((char) val);
			while ((val = in.read()) != -1) {
				if (Character.isWhitespace((char) val))
					break;
				b.append((char) val);
			}
			return Integer.parseInt(b.toString());
		} catch (final IOException e) {
			throw new RuntimeException(e);
		}
	}

	void remove(int i) {
		if (!tu[i].removed && tu[i].count < d) {
			tu[i].removed = true;
			for (int j = 0; j < tu[i].count; j++) {
				int to_remove = tu[i].roads.get(j);
				tu[to_remove].count--;
				tu[to_remove].roads.removeElement(i);
				remove(to_remove);
			}
			tu[i].count = 0;
			tu[i].roads.clear();
		}
	}
	
	int calc(int i) {
		int res = 0;
		if (!tu[i].calculated && tu[i].count >= d) {
			tu[i].calculated = true;
			res++;
			for (int j = 0; j < tu[i].count; j++) {
				int to_calc = tu[i].roads.get(j);
				if (!tu[to_calc].calculated)
					res += calc(to_calc);
			}
		}
		return res;
	}
	
	
	Vector<Integer> res;
	
	void getMax(int i) {
			if (!tu[i].printed && tu[i].count >= d) {
				tu[i].printed = true;
				res.add(i);
				for (int j = 0; j < tu[i].count; j++) {
					int to_calc = tu[i].roads.get(j);
					getMax(to_calc);
				}
			}
	}
	
	void add(int a, int b)
	{
		tu[a].id = a;
		tu[a].roads.add(b);
		tu[a].count++;
	}

	public void run(final InputStream in, PrintStream out) {
		int m = readInt(in);
		int n = readInt(in);
		d = readInt(in);
		tu = new data[m + 1];

		for (int i = 1; i <= m; i++) {
			tu[i] = new data();
			tu[i].removed = false;
			tu[i].count = 0;
			tu[i].roads = new Vector<Integer>();
		}
		
		for (int i = 0; i < n; i++) {
			int a = readInt(in);
			int b = readInt(in);
			add(a, b);
			add(b, a);
		}

		for (int i = 1; i <= m; i++) {
			remove(i);
		}

		int max_i = 0;
		int max_g = 0;

		for (int i = 1; i <= m; i++) {
			int l = calc(i);
			if (l > max_g) {
				max_g = l;
				max_i = i;
			}
		}

		if (max_g == 0) {
			out.print("NIE\n");
		} else {

			res = new Vector<Integer>();
			getMax(max_i);
			Collections.sort(res, new Comparator<Integer>() {
				@Override
				public int compare(Integer o1, Integer o2) {
					return o1 - o2;
				}
			});

			out.print(res.size() +"\n");
			for (int i = 0; i < res.size(); i++) {
				out.print(res.get(i) + " ");
			}
			out.print("\n");
		}

	}

	public static void main(final String[] args) {
		new mis().run(System.in, System.out);
	}

}