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

using namespace std;
const int maxN = 1000009;

int n,m,d,a,b,stop[maxN];
bool uzyty[maxN];
vector<int> graf[maxN];
queue<int> Q;
vector<int> Q1, wynikowo;


int BFS(int pocz)
{
    int wynik = 0;
    Q.push(pocz);
    Q1.resize(0);
    while (!Q.empty())
    {
        int u = Q.front(); Q.pop();
        wynik++;
        uzyty[u] = 1;
        Q1.push_back(u);
        for (int i = 0; i < graf[u].size(); i++)
        {
            if (!uzyty[graf[u][i]])
            {
                uzyty[graf[u][i]] = 1;
                Q.push(graf[u][i]);
            }
        }
    }
    return wynik;
}

int main()
{
    scanf("%d%d%d",&n,&m,&d);
    for (int i = 0; i < m ; i++)
    {
        scanf("%d%d",&a,&b);
        graf[a].push_back(b);
        graf[b].push_back(a);
        stop[a]++; stop[b]++;
    }
    for (int i = 1 ; i <= n; i++)
    {
        if (stop[i] < d)
        {
            Q.push(i);
        }
    }

    while (!Q.empty())
    {
        int u = Q.front(); Q.pop();
        if (!uzyty[u])
        {
            uzyty[u] = 1;
            for (int j = 0; j < graf[u].size(); j++)
            {
                if (!uzyty[graf[u][j]])
                {
                    stop[graf[u][j]]--;
                    if (stop[graf[u][j]] < d) Q.push(graf[u][j]);
                }
            }
        }
    }
    int maxim = 0;
    for (int i = 1; i <= n; i++)
    {
        if (!uzyty[i])
        {
            int c = BFS(i);
            if (c > maxim)
            {
                maxim = c;
                wynikowo = Q1;
            }
        }
    }
    if (maxim != 0)
    {
        printf("%d\n", maxim);
        sort(wynikowo.begin(), wynikowo.end());
        for (int i = 0 ; i < wynikowo.size(); i++)
            printf("%d ",wynikowo[i]);
    }
    else printf("NIE\n");
    return 0;
}