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
#include <bits/stdc++.h>
using namespace std;
const int N=2e5+5;
vector<int> e[N];
int deg[N];
bool del[N];
vector<int> res[N];
void dfs(int v, int src)
{
    if(del[v]) return;
    del[v]=1;
    res[src].push_back(v);
    for(int j: e[v]) dfs(j, src);
}
int main()
{
    int n, m, d;
    scanf("%d%d%d", &n, &m, &d);
    for(int i=0; i<m; ++i)
    {
        int a, b;
        scanf("%d%d", &a, &b);
        ++deg[a]; ++deg[b];
        e[a].push_back(b); e[b].push_back(a);
    }
    queue<int> q;
    for(int i=1; i<=n; ++i) if(deg[i]<d)
    {
        q.push(i);
        del[i]=1;
    }
    while(!q.empty())
    {
        int v=q.front();
        //printf("v=%d\n", v);
        q.pop();
        for(int j: e[v])
        {
            --deg[j];
            if(!del[j]&&deg[j]<d)
            {
                q.push(j);
                del[j]=1;
            }
        }
    }
    int mxpos=0;
    for(int i=1; i<=n; ++i)
    {
        dfs(i, i);
        if(res[i].size()>res[mxpos].size()) mxpos=i;
    }
    //for(int i=1; i<=n; ++i) printf("%d\n", res[i].size());
    if(res[mxpos].size()==0) printf("NIE\n");
    else
    {
        printf("%d\n", res[mxpos].size());
        for(int i: res[mxpos]) printf("%d ", i);
        printf("\n");
    }
    return 0;
}