#include <stdio.h>
#include <vector>
const int MAXM = 24;
std::vector<int> v[MAXM];
int res;
int popcount(int a) {
int cnt = 0;
while(a > 0) {
cnt++;
a &= a - 1;
}
return cnt;
}
void bkt(int pos, int m, int n, long long mask, int op) {
if(pos >= m) {
if(mask == (1LL << n) - 1 && popcount(op) <= popcount(res)) {
res = op;
}
} else {
int i;
bkt(pos + 1, m, n, mask, op);
op |= (1 << pos);
for(i = 0; i < (int)v[pos].size(); i++) {
mask ^= (1LL << (v[pos][i] - 1));
}
bkt(pos + 1, m, n, mask, op);
}
}
int main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif
int n, m, i, x, j, a;
scanf("%d%d", &n, &m);
for(i = 0; i < m; i++) {
scanf("%d", &x);
for(j = 0; j < x; j++) {
scanf("%d", &a);
v[i].push_back(a);
}
}
res = (1 << (m + 1)) - 1;
bkt(0, m, n, 0, 0);
x = popcount(res);
printf("%d\n", x);
for( i = 0; i < m; i++ ){
if(res & (1 << i))
printf("%d ", i + 1);
}
printf("\n");
return 0;
}
Compilation message
norela.cpp: In function 'int main()':
norela.cpp:45:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
45 | scanf("%d%d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~
norela.cpp:47:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
47 | scanf("%d", &x);
| ~~~~~^~~~~~~~~~
norela.cpp:49:12: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
49 | scanf("%d", &a);
| ~~~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
344 KB |
Output is correct |
2 |
Correct |
5 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
4 ms |
348 KB |
Output is correct |
5 |
Correct |
4 ms |
344 KB |
Output is correct |
6 |
Correct |
3 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
344 KB |
Output is correct |
2 |
Correct |
5 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
4 ms |
348 KB |
Output is correct |
5 |
Correct |
4 ms |
344 KB |
Output is correct |
6 |
Correct |
3 ms |
348 KB |
Output is correct |
7 |
Correct |
22 ms |
348 KB |
Output is correct |
8 |
Correct |
45 ms |
348 KB |
Output is correct |
9 |
Correct |
45 ms |
344 KB |
Output is correct |
10 |
Correct |
31 ms |
348 KB |
Output is correct |
11 |
Correct |
38 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
344 KB |
Output is correct |
2 |
Correct |
5 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
4 ms |
348 KB |
Output is correct |
5 |
Correct |
4 ms |
344 KB |
Output is correct |
6 |
Correct |
3 ms |
348 KB |
Output is correct |
7 |
Correct |
22 ms |
348 KB |
Output is correct |
8 |
Correct |
45 ms |
348 KB |
Output is correct |
9 |
Correct |
45 ms |
344 KB |
Output is correct |
10 |
Correct |
31 ms |
348 KB |
Output is correct |
11 |
Correct |
38 ms |
348 KB |
Output is correct |
12 |
Correct |
58 ms |
600 KB |
Output is correct |
13 |
Correct |
106 ms |
344 KB |
Output is correct |
14 |
Correct |
99 ms |
344 KB |
Output is correct |
15 |
Correct |
118 ms |
344 KB |
Output is correct |
16 |
Correct |
97 ms |
348 KB |
Output is correct |
17 |
Correct |
109 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
344 KB |
Output is correct |
2 |
Correct |
5 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
4 ms |
348 KB |
Output is correct |
5 |
Correct |
4 ms |
344 KB |
Output is correct |
6 |
Correct |
3 ms |
348 KB |
Output is correct |
7 |
Correct |
22 ms |
348 KB |
Output is correct |
8 |
Correct |
45 ms |
348 KB |
Output is correct |
9 |
Correct |
45 ms |
344 KB |
Output is correct |
10 |
Correct |
31 ms |
348 KB |
Output is correct |
11 |
Correct |
38 ms |
348 KB |
Output is correct |
12 |
Correct |
58 ms |
600 KB |
Output is correct |
13 |
Correct |
106 ms |
344 KB |
Output is correct |
14 |
Correct |
99 ms |
344 KB |
Output is correct |
15 |
Correct |
118 ms |
344 KB |
Output is correct |
16 |
Correct |
97 ms |
348 KB |
Output is correct |
17 |
Correct |
109 ms |
344 KB |
Output is correct |
18 |
Correct |
227 ms |
348 KB |
Output is correct |
19 |
Correct |
224 ms |
344 KB |
Output is correct |
20 |
Correct |
354 ms |
344 KB |
Output is correct |
21 |
Correct |
413 ms |
344 KB |
Output is correct |
22 |
Correct |
399 ms |
348 KB |
Output is correct |
23 |
Correct |
388 ms |
344 KB |
Output is correct |