#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> a[25], ans;
int vf[100];
bool found = 0;
int x[30]; /// generam toate combinatiile posibile
void backtrack(int pas){
if(pas == m + 1 && !found){
memset(vf,0,sizeof(vf));
/// cout << " == > ";
for(int i = 1;i<=m;i++){
if(x[i] == 1){
for(auto it : a[i]){
vf[it]++;
}
}
}
bool ok = 1;
for(int i = 1;i<=n;i++){
/// cout << vf[i] << ' ';
if(vf[i] == 0 || vf[i] % 2 == 0){
ok = 0;
// break;
}
}
/// cout << '\n';
if(ok){
/// prima solutie este de fapt si cea mai mica lexicografic
ans.clear();
for(int i= 1;i<=m;i++){
if(x[i] == 1){
ans.push_back(i);
// cout << i << ' ';
}
}
//cout << '\n';
}
}else{
for(int i = 0;i<=1 && !found;i++){
x[pas] = i;
backtrack(pas + 1);
}
}
}
int main(void){
cin >> n >> m;
for(int i = 1;i<=m;i++){
int q,y;
cin >> q;
for(int j = 1;j<=q;j++){
cin >> y;
a[i].push_back(y);
}
}
backtrack(1);
cout << ans.size() <<'\n';
for(auto it : ans)cout << it << ' ';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
36 ms |
596 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
36 ms |
596 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
36 ms |
596 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
36 ms |
596 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |