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
 96
 97
 98
 99
100
101
102
103
104
105
106
/* 2015
 * Maciej Szeptuch
 * II UWr
 */
#include <cstdio>
#include <vector>

int biggest,
    cities,
    component[262144],
    count[262144],
    density,
    roads,
    start, end,
    weight[262144];
bool disabled[262144];
std::vector<int> disable,
                 graph[262144];

int markComponent(int c, const int i);

int main(void)
{
    scanf("%d %d %d", &cities, &roads, &density);
    for(int r = 0; r < roads; ++ r)
    {
        scanf("%d %d", &start, &end);
        -- start, -- end;
        ++ weight[start];
        ++ weight[end];
        graph[start].push_back(end);
        graph[end].push_back(start);
    }

    for(int c = 0; c < cities; ++ c)
        if(weight[c] < density)
        {
            disable.push_back(c);
            disabled[c] = true;
        }

    while(!disable.empty())
    {
        int cur = disable.back(); disable.pop_back();
        for(unsigned int n = 0; n < graph[cur].size(); ++ n)
        {
            -- weight[graph[cur][n]];
            if(!disabled[graph[cur][n]] && weight[graph[cur][n]] < density)
            {
                disable.push_back(graph[cur][n]);
                disabled[graph[cur][n]] = true;
            }
        }
    }

    for(int c = 0, i = 1; c < cities; ++ c)
    {
        if(disabled[c]) continue;
        if(component[c]) continue;
        count[i] = markComponent(c, i);
        if(count[i] > count[biggest])
            biggest = i;

        ++ i;
    }

    if(!biggest && count[biggest] < density)
        puts("NIE");

    else
    {
        printf("%d\n", count[biggest]);
        for(int c = 0; c < cities; ++ c)
            if(component[c] == biggest)
                printf("%d ", c + 1);

        puts("");
    }

    return 0;
}

int markComponent(int c, const int i)
{
    int result = 0;
    std::vector<int> stack;
    stack.push_back(c);
    component[c] = i;
    while(!stack.empty())
    {
        ++ result;
        int cur = stack.back(); stack.pop_back();
        for(unsigned int n = 0; n < graph[cur].size(); ++ n)
        {
            int &next = graph[cur][n];
            if(!disabled[next] && !component[next])
            {
                component[next] = i;
                stack.push_back(next);
            }
        }
    }

    return result;

}