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
#include <algorithm>
#include <cstdio>
#include <vector>
#include <set>
using namespace std;

const int MAX = 200000;

#define PB push_back

vector<int> G[MAX];
bool del[MAX];
int deg[MAX];
set<pair<int,int>> Q;
vector<int> res, tmp;

int n, m, d;

void dfs(int u) {
  del[u] = true;
  tmp.PB(u);
  for (int v : G[u])
    if (!del[v])
      dfs(v);
}

int main() {
  scanf("%d %d %d", &n, &m, &d);
  while (m--)
  {
    int a, b;
    scanf("%d %d", &a, &b);
    a--, b--;
    G[a].PB(b);
    G[b].PB(a);
    deg[a]++;
    deg[b]++;
  }
  for (int i=0;i<n;i++)
    Q.insert({deg[i], i});
  while (!Q.empty() && Q.begin()->first < d)
  {
    int v = Q.begin()->second;
    del[v] = true;
    Q.erase(Q.begin());
    for (int u : G[v])
    {
      if (!del[u]) {
        Q.erase(Q.find({deg[u], u}));
        deg[u]--;
        Q.insert({deg[u], u});
      }
    }
  }

  for (int i=0;i<n;i++)
    if (!del[i]) {
      tmp.clear();
      dfs(i);
      if (tmp.size() > res.size()) res = tmp;
    }

  if (res.empty()) printf("NIE\n");
  else {
    printf("%d\n", (int)res.size());
    sort(res.begin(), res.end());
    for (int i : res)
      printf("%d ", i+1);
    printf("\n");
  }
  return 0;
}