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
144
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <iterator>
#include <string>
#include <vector>
#include <queue>
#include <bitset>
#include <utility>
#include <stack>

using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define MP make_pair
#define FOR(v,p,k) for(auto v=(p);v<=(k);++v)
#define FORD(v,p,k) for(auto v=(p);v>=(k);--v)
#define REP(i,n) for(auto i=0;i<(n);++i)
#define VAR(v,i) __typeof(i) v=(i)
#define FOREACH(i,c) for(VAR(i,(c).begin());i!=(c).end();++i)
#define PB push_back
#define ST first
#define ND second
#define SIZE(x) (int)x.size()
#define ALL(c) c.begin(),c.end()

#define ODD(x) ((x)%2)
#define EVEN(x) (!(ODD(x)))

template <typename T>
inline void eraseElement(std::vector<T> &vec, const T &val) {
  vec.erase(std::remove(vec.begin(), vec.end(), val), vec.end());
}

#define MAXN 200001

VVI neigh(MAXN);
VI scc_id(MAXN);
VI scc_cnt(MAXN);
VI deleted(MAXN);

int n, m, d;

void dfs_remove_low_degree() {
    queue<int> q;
    VI sizes(n+1);
    FOR(v, 1, n) {
      if (neigh[v].size() < d) q.push(v);
      sizes[v] = neigh[v].size();
    }

    while (!q.empty()) {
      int from = q.front();
      q.pop();
      if (deleted[from]) continue;

      if (sizes[from] >= d) continue;

      for (auto next : neigh[from]) {
        if (deleted[from]) continue;

        q.push(next);
        --sizes[next];
      }
      neigh[from].clear();
      sizes[from] = 0;
      deleted[from]=1;
    }

    FOR(v, 1, n) {
      if (deleted[v] || sizes[v] == neigh[v].size()) continue;
      for (auto& next : neigh[v]) {
        if (deleted[next]) next = -1;
      }
      eraseElement(neigh[v], -1);
    }
}

void dfs_detect_components() {
    stack<PII> q;
    FOR(v, 1, n) {
      if (!deleted[v]) q.push(MP(v,v));
    }

    while (!q.empty()) {
      int prev = q.top().first;
      int from = q.top().second;
      q.pop();
      if (scc_id[prev]) continue;

      scc_id[prev] = from;
      ++scc_cnt[from];

      for (auto next : neigh[prev]) {
        if (scc_id[next]) continue;

        q.push(MP(next,from));
      }
    }

    int best_cnt = 0;
    int best_id = 0;
    FOR(v, 1, n) {
      if (best_cnt < scc_cnt[v]) {
        best_cnt = scc_cnt[v];
        best_id = v;
      }
    }

    if (best_cnt > 0) {
        cout << best_cnt << "\n";
        FOR(v, 1, n) {
          if (scc_id[v] == best_id) {
              cout << v << (--best_cnt ? " " : "");
          }
        }
    } else {
      cout << "NIE";
    }
    cout << endl;
}


int main() {
  ios_base::sync_with_stdio(0);

  cin >> n >> m >> d;

  REP(i, m) {
    int a, b;
    cin >> a >> b;
    neigh[a].PB(b);
    neigh[b].PB(a);
  }
  dfs_remove_low_degree();
  dfs_detect_components();

  return 0;
}