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

#define MAXM 2000001

int D;
int gmax;
std::vector<int> graf[MAXM];

int stopien[MAXM] = {0};
int done[MAXM] = {0};

int sklad[MAXM] = {0};

void wywal(int n) {
    if (done[n])
        return;

    if (stopien[n] >= D)
        return;

    done[n] = 1;

    for (int i=0; i<graf[n].size(); ++i) {
        int next = graf[n][i];
        --stopien[next];
        wywal(next);
    }
}

int mieszaj(int I, int n) {
    if (stopien[n] < D)
        return 0;

    if (sklad[n] != 0)
        return 0;

    sklad[n] = I;
    int sum = 1;

    for (int k = 0; k < graf[n].size(); ++k) {
        sum += mieszaj(I, graf[n][k]);
    }
    return sum;
}

int main() {
    int kmax;
    scanf("%d%d%d", &gmax, &kmax, &D);
    for (int i=0; i<kmax; ++i) {
        int a, b;
        scanf("%d%d",&a,&b);
        graf[a].push_back(b);
        graf[b].push_back(a);

        stopien[a]++;
        stopien[b]++;
    }
    
    for (int i=1; i<=gmax; ++i) {
        wywal(i);
    }

    int maxi = 0;
    int maxg = 0;
    for (int i=1; i<=gmax; ++i) {
        int ile = mieszaj(i,i);
        if (ile > maxg) {
            maxg = ile;
            maxi = i;
        }
    }

    if (maxg == 0) {
        printf("NIE\n");
        return 0;
    }

    printf("%d\n", maxg);
    for (int i=1; i<=gmax; ++i) {
        if (sklad[i] == maxi)
            printf("%d ", i);
    }

    return 0;
}