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 | #include <stdio.h>
#include <vector>
#include <set>
#include <utility>
using namespace std;
int n, m, d;
int a, b;
vector <int> graf[200001];
set < pair < int, int > > miasta;
int stopien[200001];
pair < int, int > kandydat;
bool usuniete[200001];
int sasiad;
int licznosc = 0;
bool da_sie = true;
bool odwiedzone[200001];
void dfs(int w);
int licznosc_spojnej = 0;
int lista[200001];
int rekord = 0;
int lista_rekord[200001];
bool wynikowy[200001];
int main()
{
scanf("%d", &n);
scanf("%d", &m);
scanf("%d", &d);
for(int i = 0; i < m; i++)
{
scanf("%d", &a);
scanf("%d", &b);
graf[a-1].push_back(b-1);
graf[b-1].push_back(a-1);
stopien[a-1]++;
stopien[b-1]++;
}
for(int i = 0; i < n; i++)
{
miasta.insert(make_pair(stopien[i], i));
}
while(1)
{
if(miasta.size() == 0) { printf("NIE\n"); da_sie = false; break; }
kandydat = *(miasta.begin());
if(kandydat.first >= d) break;
else
{
miasta.erase(miasta.begin());
usuniete[kandydat.second] = true;
stopien[kandydat.second] = 0;
for(int i = 0; i < graf[kandydat.second].size(); i++)
{
sasiad = graf[kandydat.second].at(i);
if(usuniete[sasiad] == false)
{
miasta.erase(miasta.find(make_pair(stopien[sasiad], sasiad)));
stopien[sasiad]--;
miasta.insert(make_pair(stopien[sasiad], sasiad));
}
}
}
}
if(da_sie)
{
for(int i = 0; i < n; i++)
{
if(usuniete[i] == false && odwiedzone[i] == false)
{
dfs(i);
if(licznosc_spojnej > rekord)
{
rekord = licznosc_spojnej;
for(int j = 0; j < licznosc_spojnej; j++) lista_rekord[j] = lista[j];
}
licznosc_spojnej = 0;
}
}
printf("%d\n", rekord);
for(int i = 0; i < rekord; i++) wynikowy[lista_rekord[i]] = true;
for(int i = 0; i < n; i++)
{
if(wynikowy[i]) printf("%d ", i+1);
}
printf("\n");
}
return 0;
}
void dfs(int w)
{
odwiedzone[w] = true;
lista[licznosc_spojnej] = w;
licznosc_spojnej++;
for(int i = 0; i < graf[w].size(); i++)
{
if(usuniete[graf[w].at(i)] == false && odwiedzone[graf[w].at(i)] == false) dfs(graf[w].at(i));
}
}
|