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
#include <iostream>
#include <list>

using namespace std;

class Node {
public:
    int number;
    int visit_round;    
    list<Node*> neighbours;
public:
    Node();
};

Node :: Node() : visit_round(0) {
    
}

int main(int argc, char** argv) {

    ios_base::sync_with_stdio(0);
    
    int n, m, d, a, b;
    
    cin >> n;
    cin >> m;
    cin >> d;
    
    list<Node*> nodes;
    Node** node_refs = new Node*[n];
    
    for (int i=0; i<n; i++) {
        Node* node = new Node();
        node->number = i + 1;
        
        nodes.push_back(node);
        node_refs[i] = node;
    }
    
    for (int i=0; i<m; i++) {
        cin >> a;
        cin >> b;
        node_refs[a-1]->neighbours.push_back(node_refs[b-1]);
        node_refs[b-1]->neighbours.push_back(node_refs[a-1]);
    }
    
    int nodes_size = nodes.size();
    int counter = 0;
    for (;;) {
        for (list<Node*>::iterator i = nodes.begin(); i != nodes.end();) {
            if ((*i)->neighbours.size() < d) {
                for (list<Node*>::iterator j=(*i)->neighbours.begin(); j != (*i)->neighbours.end(); j++) {
                    (*j)->neighbours.remove(*i);
                }
                i = nodes.erase(i);
            } else {
                ++i;
            }
        }
        if (nodes.size() == 0 || counter == 2) {
            break;
        } else if (nodes.size() == nodes_size) {
            counter++;
        } else {
            nodes_size = nodes.size();
        }
    }
  
    
    if (nodes.size() == 0) {
        cout << "NIE" << endl;
    } else {
        cout << nodes.size() << endl;
        for (list<Node*>::iterator i = nodes.begin(); i != nodes.end(); i++) {
            cout << (*i)->number << " ";
        }
        cout << endl;
    }
    
    return 0;
}