// #include <bits/stdc++.h>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <vector>
#include <iomanip>
#include <string>
#include <queue>
#include <set>
#include <deque>
using namespace std;
// #define int long long
#define endl "\n"
#define fi first
#define se second
const int M=1e9+7;
// const int inf = 1e15;
const int LOG=17;
const int N=2e5+5;
int n , m , c , w , k , t=1 , q=1 , x , y , z , l , r;
bool f=0;
int ans=0;
int bp=100;
int vi[100];
vector<int>sp;
vector<vector<int>>a;
void rec(int i){
for (int j=1;j>=0;j--){
if (__builtin_popcount(ans)+j>=bp)continue;
if (j){
ans+=(1<<i);
for (int k:a[i]){
vi[k]^=1;
if (vi[k])c++;
else c--;
}
}
if (c==n){
sp.push_back(ans);
bp=min(bp,__builtin_popcount(ans));
}
if (i!=m-1)rec(i+1);
if (j){
ans-=(1<<i);
for (int k:a[i]){
vi[k]^=1;
if (vi[k])c++;
else c--;
}
}
}
}
void solve(){
cin >> n >> m;
for (int i=0;i<m;i++){
cin >> k;
vector<int>b(k);
for (int j=0;j<k;j++){
cin >> b[j];
}
a.push_back(b);
}
rec(0);
for (int ans:sp){
if (__builtin_popcount(ans)!=bp)continue;
cout << __builtin_popcount(ans) << endl;
for (int i=0;i<m;i++){
if (ans&(1<<i)){
cout << i+1 << " ";
}
}
cout << endl;
return;
}
}
signed main()
{
// #ifndef ONLINE_JUDGE
// freopen("input.txt","r" ,stdin);
// freopen("output.txt","w",stdout);
// #endif
// ios::sync_with_stdio(0);//DO NOT USE IN INTERACTIVE
// cin.tie(0), cout.tie(0);//DO NOT USE IN INTERACTIVE
// cout << fixed << setprecision(9);
// srand(time(0));
// int t=1;
// cin >> t;
for (int _=1;_<=t;_++){
solve();
q++;
}
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |