-
Notifications
You must be signed in to change notification settings - Fork 4
/
193.cpp
54 lines (44 loc) · 1006 Bytes
/
193.cpp
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
#include <iostream>
#include <cstring>
using namespace std;
int n, m, k, best, a, b;
bool graph[101][101], black[101], visited[101], bb[101];
bool canBeBlack(int node) {
for (int i = 1; i <= n; i++) if (graph[node][i] and black[i]) return false;
return true;
}
void dfs(int node, int nb) {
visited[node] = true;
if (node == n + 1) {
if (best < nb) {
best = nb;
memcpy(bb, black, sizeof(black));
}
return;
}
if (canBeBlack(node)) {
black[node] = true;
dfs(node + 1, nb + 1);
black[node] = false;
}
dfs(node + 1, nb);
visited[node] = false;
}
int main() {
cin >> m;
while (m--) {
cin >> n >> k;
memset(graph, 0, sizeof(graph));
for (int i = 1; i <= k; i++) { cin >> a >> b; graph[a][b] = true; graph[b][a] = true; }
dfs(1, 0);
cout << best << endl;
for (int i = 1; i <= n; i++)
if (bb[i]) {
best--;
cout << i;
if (best != 0) cout << ' ';
}
cout << endl;
}
return 0;
}