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
#include <algorithm>
#include <cstdio>
#include <set>
#include <vector>

using namespace std;

const int MAXN = 200005;

int n, m, d;

vector<int> e[MAXN];
int deg[MAXN];
set<pair<int, int> > S;
bool sol[MAXN];

vector<int> res;
vector<int> cur;
bool vis[MAXN];

void dfs(int u) {
  vis[u] = true;
  cur.push_back(u);
  for (int i = 0; i < (int) e[u].size(); ++i) {
    if (sol[e[u][i]] && !vis[e[u][i]]) {
      dfs(e[u][i]);
    }
  }
}

int main() {
  scanf("%d%d%d", &n, &m, &d);
  for (int i = 0; i < m; ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    --a; --b;
    e[a].push_back(b);
    e[b].push_back(a);
    ++deg[a];
    ++deg[b];
  }
  for (int i = 0; i < n; ++i) {
    S.insert(make_pair(deg[i], i));
    sol[i] = true;
  }
  while (!S.empty()) {
    pair<int, int> fst = *S.begin();
    if (fst.first < d) {
      S.erase(S.begin());
      sol[fst.second] = false;
      for (int i = 0; i < (int) e[fst.second].size(); ++i) {
        pair<int, int> toRemove = make_pair(deg[e[fst.second][i]], e[fst.second][i]);
        --deg[fst.second];
        --deg[e[fst.second][i]];
        if (sol[e[fst.second][i]]) {
          S.erase(toRemove);
          S.insert(make_pair(toRemove.first - 1, toRemove.second));
        }
      }
    } else {
      break;
    }
  }
  if (S.empty()) {
    printf("NIE\n");
    return 0;
  }
  for (int i = 0; i < n; ++i) {
    if (sol[i] && !vis[i]) {
      cur.clear();
      dfs(i);
      if (cur.size() > res.size()) {
        res = cur;
      }
    }
  }
  printf("%d\n", (int) res.size());
  sort(res.begin(), res.end());
  for (int i = 0; i < (int) res.size(); ++i) {
    printf("%d ", res[i] + 1);
  }
  printf("\n");
  return 0;
}