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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

typedef long long LL;

#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define MP make_pair
#define ST first
#define ND second
#define PB push_back
#define FOR(i,b,e) for(int i=(b); i<=(e); ++i)
#define FORD(i,b,e) for(int i=(b); i>=(e); --i)
#define REP(i,n) for(int i=0; i<n; ++i)
#define VAR(v,n) __typeof(n) v = (n)
#define SIZE(x) ((int)(x).size())
#define FOREACH(i,x) for(VAR(i,(x).begin()); i!=(x).end(); ++i)
#define SC scanf
#define PR printf

template <typename V,
          typename E>
struct Graph {
    struct Ed : E {
        int v;
        Ed(E p, int w) : E(p), v(w) {};
    };
    struct Ve : V, vector<Ed> {};

    vector<Ve> g;
    Graph(int n = 0) : g(n) {};

    void edge(int b, int e, E d = E()) {
        g[b].PB(Ed(d,e));
        g[e].PB(Ed(d,b));
    }

    void degree(){
        FOREACH(it, g)
            it->deg=SIZE(*it);
    }

    void set_to_remove(int d) {
        FOREACH(it, g) it->rem=0;

        vector<int> st(SIZE(g));
        int b=0, e=0;
        REP(i, SIZE(g)) {
            if(g[i].deg < d) {
                st[e++]=i;
                g[i].rem = 1;
            }
        }
        while(b<e) {
            int x=st[--e];
            FOREACH(it, g[x]) {
                if(g[it->v].deg--==d) {
                    st[e++]=it->v;
                    g[it->v].rem = 1;
                }
            }
        }
    }

    void scc(){
        int n=0;
        int s=0;
        int b,e;

        FOREACH(it, g) it->s=0;

        vector<int> st(SIZE(g));
        REP(i, SIZE(g)) {
            if(!g[i].s && !g[i].rem){
                st[b=e=0]=i;
                g[i].n=++n;
                g[i].s=(s=1);
                while(b<=e) {
                    int x=st[b++];
                    FOREACH(it, g[x]) {
                        if(!g[it->v].s && !g[it->v].rem) {
                            g[st[++e] = it->v].s=++s;
                            g[it->v].n=n;
                        }
                    }
                }
            }
        }
    }

    void print_max_scc(){
        int m=0,id=0;
        REP(i,SIZE(g)) {
            if(g[i].s > m){
                m=g[i].s;
                id=g[i].n;
            }
        }
        if(id){
            printf("%d\n", m);
            REP(i,SIZE(g))
                if(g[i].n==id)
                    printf("%d ",i+1);
            printf("\n");
        }
        else
            printf("NIE\n");
    }
};

struct V {
    int deg;
    int rem;
    int n;
    int s;
};

struct E {};

int main() {
    int n,m,b,e,d;
    SC("%d %d %d", &n, &m, &d);
    Graph<V,E> graph(n);
    REP(i,m) {
        SC("%d %d", &b, &e);
        graph.edge(b-1,e-1);
    }

    graph.degree();
    graph.set_to_remove(d);
    graph.scc();

    graph.print_max_scc();
    //FOREACH(it, graph.g) printf("%d %d %d\n", it->rem, it->n, it->s);
    return 0;
}