-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path193.cpp
78 lines (68 loc) · 1.44 KB
/
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "bits/stdc++.h"
using namespace std;
int ans;
vector<int> ansv;
void printVec (vector<int> & v) {
for (int i = 0; i < v.size(); ++i){
if (i != v.size() -1)
printf("%d ",v[i]);
else
printf("%d",v[i]);
}
printf("\n");
}
bool adjToBlack (bitset<110> & color, vector <vector <int> > &adj, int node) {
for (int i = 0; i < adj[node].size(); ++i) {
if (color[adj[node][i]] == 1) {
return true;
}
}
return false;
}
void numBlack (vector <vector <int> > &adj, int node, int n, bitset<110> & color) {
if (node == n + 1) {
int cont = 0;
std::vector<int> v;
for (int i = 0; i <= 100; ++i) {
if (color[i]) {
++cont;
v.push_back(i);
//cout << i << " ";
}
}
if (cont > ans) {
ans = cont;
ansv = v;
}
return;
}
vector<int> black;
if (!adjToBlack(color, adj, node)) {
color[node] = 1;
numBlack(adj, node + 1, n, color);
}
color[node] = 0;
numBlack(adj, node + 1, n, color);
}
int main(int argc, char const *argv[]) {
int TC;
scanf("%d",&TC);
while (TC--) {
int n, m;
scanf("%d%d",&n,&m);
vector< vector <int> > adj(n + 1);
for (int i = 0; i < m; ++i) {
int a, b;
scanf("%d%d",&a,&b);
adj[a].push_back(b);
adj[b].push_back(a);
}
cin.ignore();
ans = -1;
bitset<110> color;
numBlack(adj, 1, n, color);
printf("%d\n", ans);
printVec(ansv);
}
return 0;
}