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
#include <cstdio>
#include <vector>
#include <queue>

using namespace std;


int n, m, d, deg[200000], x, y;
bool mark[200000];

vector<int> neig[200000];
vector<int>::iterator it;
vector<int> odp, nodp;
queue<int> que;


int main()
{
    scanf("%d%d%d", &n, &m, &d);
    for (int i=0; i<n; i++) {deg[i]=0; mark[i]=0;}
    for (int i=0; i<m; i++) {
        scanf("%d%d", &x, &y); x--; y--;
        deg[x]++;
        deg[y]++;
        neig[x].push_back(y);
        neig[y].push_back(x);
    }

    for (int i=0; i<n; i++)
        if (deg[i]<d) {que.push(i); mark[i]=1;}

    while (!que.empty()) {
        x = que.front();
        que.pop();
        for (it=neig[x].begin(); it!=neig[x].end(); it++) {
            deg[*it]--;
            if (deg[*it]<d && mark[*it]==0) {
                mark[*it] = 1;
                que.push(*it);
            }
        }
    }

    for (int i=0; i<n; i++) {
        if (mark[i]==0) {
            nodp.clear();
            nodp.push_back(i);
            que.push(i);
            mark[i] = 1;
            while (!que.empty()) {
                x = que.front();
                que.pop();
                for (it=neig[x].begin(); it!=neig[x].end(); it++) {
                    if (mark[*it]==0) {
                        mark[*it] = 1;
                        nodp.push_back(*it);
                        que.push(*it);
                    }
                }
            }
        }
        if (nodp.size() > odp.size()) odp = nodp;
    }

    if (odp.size() > 0) {
        printf("%d\n", odp.size());
        for (it=odp.begin(); it!=odp.end(); it++) printf("%d ", *it+1);
        printf("\n");
    }
    else printf("NIE\n");
}