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
#include <cstdio>
#include <set>
#include <algorithm>
#include <deque>
#include <typeinfo>
#include <iostream>
using namespace std;
int n,m,d;
bool is_bad[200010];
set<int>G[200010];
vector<vector<int>> wc; //well comunicated subgraphs

void dfs(int v) {
    wc.back().push_back(v);
    is_bad[v] = true;
    for ( auto u : G[v] ) {
        if (!is_bad[u]) {
            dfs(u);
        }
    }
}

int main() {
	scanf("%d%d%d", &n, &m, &d);
	int a, b;
	deque<int>bad;

	for (int i = 0; i < m; i++) {
		scanf("%d%d", &a, &b);
		G[a].insert(b);
		G[b].insert(a);
	}

	for (int i = 1; i <= n; i++) {
        if (G[i].size() < d) {
            bad.push_back(i);
            is_bad[i] = true;
        }
    }

    while (!bad.empty()) {
        a = bad.front();
        bad.pop_front();
        for (auto v : G[a]) {
            G[v].erase(a);
            if ( !is_bad[v] && G[v].size() < d) {
                bad.push_back(v);
                is_bad[v] = true;
            }
        }
        G[a].clear();
    }

    for ( int a = 1; a <= n; a++ ) {
        if (!is_bad[a]) {
            wc.push_back(vector<int>());
            dfs(a);
        }
    }

    int max_size=0, max_i;
    for ( int i = 0; i < wc.size(); i++ ) {
        if (wc[i].size() > max_size) {
            max_size = wc[i].size();
            max_i = i;
        }
    }

    if (max_size > 0) {
        sort( wc[max_i].begin(), wc[max_i].end() );
        printf("%d\n", max_size);
        for (auto a : wc[max_i]) {
            printf("%d ", a);
        }
    } else {
        printf("NIE");
    }

    return 0;
}