#include "bits/stdc++.h"
using namespace std;
#ifdef debug
#include "debug.hpp"
#else
#define dbg(...)
#define dbgx(x)
#define line()
#endif
#define int long long
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define size(x) (int)(x.size())
void _() {
int n, m;
cin >> n >> m;
vi opr[m + 1];
for (int i = 1; i <= m; ++i) {
int q;
cin >> q;
while (q--) {
int x;
cin >> x;
opr[i].push_back(x);
}
}
vi ans = {(int)(1e9)};
for (int mask = 1; mask <= (1LL << m); ++mask) {
vi mark(n + 1, false);
for (int i = 0; i < m; ++i) {
if ((mask & (1LL << i)) == false)
continue;
for (int &q : opr[i + 1])
mark[q] = !mark[q];
}
bool ok = true;
for (int i = 1; i <= n; ++i) {
if (mark[i] == false) {
ok = false;
break;
}
}
if (ok == false)
continue;
vi idx = {};
for (int i = 0; i < m; ++i)
if (mask & (1LL << i))
idx.push_back(i + 1);
if (size(ans) > size(idx))
ans = idx;
else if (size(ans) == size(idx)) ans = min(ans, idx);
}
assert(ans.back() != (int)(1e9));
cout << size(ans) << '\n';
for (int &v : ans)
cout << v << ' ';
cout << '\n';
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
// freopen("in.txt", "r", stdin);
int t = 1;
// cin >> t;
for (int cs = 1; cs <= t; ++cs) {
_();
}
return 0;
}
| # | 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... |