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
#include <cstdio>
#include <vector>
#include <queue>
using namespace std;
#define MAXN 200007
vector<int> adj[MAXN];
queue<int> process;
int lvl[MAXN];
int v, e, a, b, d;
bool bad[MAXN];

void processing(){
  while(!process.empty()) {
    int x = process.front();
    bad[x] = true;
    process.pop();
    for(int i = 0; i < adj[x].size(); i++) {
      lvl[adj[x][i]]--;
      if (lvl[adj[x][i]] == d - 1) {
        process.push(adj[x][i]);
      }
    }
  }
}

int group[MAXN], biggest, its_size, current, current_size;
void dfs(int x){
  current_size++;
  group[x] = current;
  for(int i = 0; i < adj[x].size(); i++) {
    if (!group[adj[x][i]] && !bad[adj[x][i]])
      dfs(adj[x][i]);
  }
}

void groups() {
  current = 0;
  current_size = 0;
  for(int i = 0; i < v; i++){
    if (bad[i] || group[i])
      continue;
    current++;
    current_size = 0;
    dfs(i);
    if (current_size > its_size) {
      biggest = current;
      its_size = current_size;
    }
  }
}
int main(){
  scanf("%d%d%d",&v,&e,&d);
  for(int i = 0; i < e; i++) {
    scanf("%d%d",&a,&b); a--; b--;
    adj[a].push_back(b);
    adj[b].push_back(a);
    lvl[a]++; lvl[b]++;
  }
  for(int i = 0; i < v; i++) {
    if (lvl[i] < d){
      process.push(i);
   }
  }

  processing();
  groups();
  if (its_size == 0) {
    printf("NIE\n");
    return 0;
  }
  printf("%d\n", its_size);
  for(int i = 0; i < v; i++)
    if (group[i] == biggest)
      printf("%d ", i + 1);
  printf("\n");

}