#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll menor,N,M,mascaras[30],alvo,menormask;
void brute(int atual,ll bitmask,int qtd,ll outramask){
if(atual == M){
if(bitmask != alvo) return;
if(qtd < menor){
menor = qtd;
menormask = outramask;
}
else if(qtd == menor){
for(ll i = 0;i<M;i++){
if((outramask & (1LL << i)) && !(menormask & (1LL << i)) ){
menormask = outramask;
break;
}
}
}
return;
}
brute(atual+1, bitmask,qtd, outramask );
brute(atual+1, bitmask ^ mascaras[atual], qtd+1, outramask | (1LL << atual) );
}
int main(){
cin >> N >> M;
menor = 2*M;
alvo = (1LL << N) - 1;
for(ll i = 0;i<M;i++){
ll x;
cin >> x;
while(x--){
ll y;
cin >> y;
y--;
mascaras[i] |= (1LL << y);
}
}
brute(0,0,0,0);
cout << menor << endl;
for(ll i = 0;i<M;i++){
if(menormask & (1LL << i)){
cout << i + 1 << " ";
}
}
cout << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
488 KB |
Output is correct |
3 |
Correct |
2 ms |
544 KB |
Output is correct |
4 |
Correct |
3 ms |
544 KB |
Output is correct |
5 |
Correct |
3 ms |
544 KB |
Output is correct |
6 |
Correct |
3 ms |
544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
488 KB |
Output is correct |
3 |
Correct |
2 ms |
544 KB |
Output is correct |
4 |
Correct |
3 ms |
544 KB |
Output is correct |
5 |
Correct |
3 ms |
544 KB |
Output is correct |
6 |
Correct |
3 ms |
544 KB |
Output is correct |
7 |
Correct |
10 ms |
544 KB |
Output is correct |
8 |
Correct |
13 ms |
544 KB |
Output is correct |
9 |
Correct |
21 ms |
544 KB |
Output is correct |
10 |
Correct |
19 ms |
544 KB |
Output is correct |
11 |
Correct |
15 ms |
544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
488 KB |
Output is correct |
3 |
Correct |
2 ms |
544 KB |
Output is correct |
4 |
Correct |
3 ms |
544 KB |
Output is correct |
5 |
Correct |
3 ms |
544 KB |
Output is correct |
6 |
Correct |
3 ms |
544 KB |
Output is correct |
7 |
Correct |
10 ms |
544 KB |
Output is correct |
8 |
Correct |
13 ms |
544 KB |
Output is correct |
9 |
Correct |
21 ms |
544 KB |
Output is correct |
10 |
Correct |
19 ms |
544 KB |
Output is correct |
11 |
Correct |
15 ms |
544 KB |
Output is correct |
12 |
Correct |
14 ms |
544 KB |
Output is correct |
13 |
Correct |
22 ms |
544 KB |
Output is correct |
14 |
Correct |
35 ms |
544 KB |
Output is correct |
15 |
Correct |
24 ms |
544 KB |
Output is correct |
16 |
Correct |
23 ms |
544 KB |
Output is correct |
17 |
Correct |
22 ms |
544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
488 KB |
Output is correct |
3 |
Correct |
2 ms |
544 KB |
Output is correct |
4 |
Correct |
3 ms |
544 KB |
Output is correct |
5 |
Correct |
3 ms |
544 KB |
Output is correct |
6 |
Correct |
3 ms |
544 KB |
Output is correct |
7 |
Correct |
10 ms |
544 KB |
Output is correct |
8 |
Correct |
13 ms |
544 KB |
Output is correct |
9 |
Correct |
21 ms |
544 KB |
Output is correct |
10 |
Correct |
19 ms |
544 KB |
Output is correct |
11 |
Correct |
15 ms |
544 KB |
Output is correct |
12 |
Correct |
14 ms |
544 KB |
Output is correct |
13 |
Correct |
22 ms |
544 KB |
Output is correct |
14 |
Correct |
35 ms |
544 KB |
Output is correct |
15 |
Correct |
24 ms |
544 KB |
Output is correct |
16 |
Correct |
23 ms |
544 KB |
Output is correct |
17 |
Correct |
22 ms |
544 KB |
Output is correct |
18 |
Correct |
44 ms |
544 KB |
Output is correct |
19 |
Correct |
42 ms |
544 KB |
Output is correct |
20 |
Correct |
83 ms |
564 KB |
Output is correct |
21 |
Correct |
94 ms |
564 KB |
Output is correct |
22 |
Correct |
81 ms |
564 KB |
Output is correct |
23 |
Correct |
81 ms |
564 KB |
Output is correct |