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
#include <iostream>
#include <set>
#include <algorithm>
using namespace std;

set<int> G[200001];
int V, E, d, a, b, R[200001], vis[200001], best;

void DFS(int v) {
    if (G[v].size() >= d) {
        return;
    }

    for (set<int>::iterator it = G[v].begin(); it != G[v].end(); it++) {
        G[*it].erase(v);
        // cout << "ERASING " << v << " FROM " << *it << endl;
    }
    for (set<int>::iterator it = G[v].begin(); it != G[v].end(); it++) {
        DFS(*it);
    }
    G[v].clear();
}

void DFS2(int v, int k) {
    if (vis[v]) {
        return;
    }
    // cout << "DFS2 " << v << " " << k << endl;
    vis[v] = k;
    R[k]++;
    if (R[k] > R[best]) {
        best = k;
    }

    for (set<int>::iterator it = G[v].begin(); it != G[v].end(); it++) {
        DFS2(*it, k);
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin >> V >> E >> d;
    for (int i = 0; i < E; i++) {
        cin >> a >> b;
        G[a].insert(b);
        G[b].insert(a);
    }
    for (int i = 1; i <= V; i++) {
        DFS(i);
    }

    for (int i = 1; i <= V; i++) {
        DFS2(i, i);
    }
    if (R[best] == 1) {
        cout << "NIE" << endl;
    } else {
        cout << R[best] << endl;
        for (int i = 1; i <= V; i++) {
            if (vis[i] == best) {
                cout << i << " ";
            }
        }
        cout << endl;
    }

    return 0;
}