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
107
108
109
110
111
112
113
114
115
116
117
118
119
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <stack>
#include <iostream>
#include <set>

using namespace std;

int n, m, d;
vector<int> *E;
int *D;

void shrink(int i) {
    //cout << i << endl;
    if (D[i] == -1) return;
    if (D[i] < d) {
        D[i] = -1;
        for(vector<int>::iterator it = E[i].begin(); it != E[i].end(); it++) {
            int j = *it;
            if (j == -1) continue;
            *it = -1;
            D[j]--;
            shrink(j);
        }
    }
}

void shrink2(int i) {
    if (D[i] == -1) return;
    if (D[i] < d) {
        stack<int> s;
        set<int> ss;
        s.push(i);
        ss.insert(i);
        while(s.size() > 0) {
            i = s.top();
            s.pop();
            ss.erase(i);
            if (D[i] == -1 || D[i] >= d) continue;
            D[i] = -1;
            for(vector<int>::iterator it = E[i].begin(); it != E[i].end(); it++) {
                int j = *it;
                if (D[j] == -1) continue;
//                if (j == -1) continue;
//                *it = -1;
                D[j]--;
                if (ss.find(j) == ss.end()) {
                    s.push(j);
                    ss.insert(j);
                }
            }
        }
    }
}

int main() {
    cin >> n >> m >> d;
    D = new int[n+1];
    E = new vector<int>[n+1];
    for(int i=1; i<=n; i++) {
        D[i] = 0;
//        E[i] = new vector<int>();
    }

    //cout << "." << endl;
    for(int i=0; i<m; i++) {
        int a, b;
        cin >> a >> b;
        D[a]++;
        D[b]++;
        E[a].push_back(b);
        E[b].push_back(a);
    }

//    cout << "." << endl;
    for(int i=1; i<=n; i++) {
        shrink2(i);
  //      cout << endl;
    }
    //cout << "." << endl;

    vector<int> candidate;
    stack<int> stack;
    for(int i=1; i<=n; i++) {
        vector<int> current;
        if(D[i] < d) continue;
        D[i] = 0;
        current.push_back(i);
        stack.push(i);
        while(stack.size() > 0) {
            int j = stack.top();
            stack.pop();
            for(vector<int>::iterator it = E[j].begin(); it != E[j].end(); it++) {
                int k = *it;
                if (k == -1 || D[k] < d) continue;
                D[k] = 0;
                current.push_back(k);
                stack.push(k);
            }
        }
        if(current.size() > candidate.size()) {
            candidate = current;
        }
    }
    if (candidate.size() > 1) {
        sort(candidate.begin(), candidate.end());
        cout << candidate.size() << endl;
        for(vector<int>::iterator it = candidate.begin(); it != candidate.end(); it++) {
            cout << *it << " ";
        }
        cout << endl;
    } else {
        cout << "NIE" << endl;
    }

    return 0;
}