#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10
#define ll long long
#define double long double
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define aint(a) (a).begin(), (a).end()
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000000007
#define PI 3.14159265359
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005ll
#define CODE_START ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll n,m,ans,sz=LINF,a[30];
void solve(ll nrcar,ll x,ll nrvraj,ll vraj){
if(x==m){
if(nrcar==(1ll<<n)-1){
if(sz>vraj){
sz=vraj;
ans=nrvraj;
}
}
return;
}
solve(nrcar^a[x],x+1,nrvraj^(1<<x),vraj+1);
solve(nrcar,x+1,nrvraj,vraj);
}
int32_t main(){
CODE_START;
cin>>n>>m;
for(ll i=0;i<m;i++)
{
ll y;
cin>>y;
for(ll j=0;j<y;j++)
{
ll x;
cin>>x;
x--;
a[i]^=(1ll<<x);
}
}
solve(0,0,0,0);
cout<<sz<<endl;
for(ll i=0;i<m;i++)
{
if((1ll<<i)&ans){
cout<<i+1<<' ';
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
364 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
364 KB |
Output is correct |
5 |
Correct |
2 ms |
364 KB |
Output is correct |
6 |
Correct |
2 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
364 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
364 KB |
Output is correct |
5 |
Correct |
2 ms |
364 KB |
Output is correct |
6 |
Correct |
2 ms |
364 KB |
Output is correct |
7 |
Correct |
7 ms |
364 KB |
Output is correct |
8 |
Correct |
14 ms |
364 KB |
Output is correct |
9 |
Correct |
14 ms |
364 KB |
Output is correct |
10 |
Correct |
14 ms |
492 KB |
Output is correct |
11 |
Correct |
13 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
364 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
364 KB |
Output is correct |
5 |
Correct |
2 ms |
364 KB |
Output is correct |
6 |
Correct |
2 ms |
364 KB |
Output is correct |
7 |
Correct |
7 ms |
364 KB |
Output is correct |
8 |
Correct |
14 ms |
364 KB |
Output is correct |
9 |
Correct |
14 ms |
364 KB |
Output is correct |
10 |
Correct |
14 ms |
492 KB |
Output is correct |
11 |
Correct |
13 ms |
364 KB |
Output is correct |
12 |
Correct |
14 ms |
364 KB |
Output is correct |
13 |
Correct |
31 ms |
364 KB |
Output is correct |
14 |
Correct |
26 ms |
364 KB |
Output is correct |
15 |
Correct |
26 ms |
364 KB |
Output is correct |
16 |
Correct |
26 ms |
364 KB |
Output is correct |
17 |
Correct |
26 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
364 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
364 KB |
Output is correct |
5 |
Correct |
2 ms |
364 KB |
Output is correct |
6 |
Correct |
2 ms |
364 KB |
Output is correct |
7 |
Correct |
7 ms |
364 KB |
Output is correct |
8 |
Correct |
14 ms |
364 KB |
Output is correct |
9 |
Correct |
14 ms |
364 KB |
Output is correct |
10 |
Correct |
14 ms |
492 KB |
Output is correct |
11 |
Correct |
13 ms |
364 KB |
Output is correct |
12 |
Correct |
14 ms |
364 KB |
Output is correct |
13 |
Correct |
31 ms |
364 KB |
Output is correct |
14 |
Correct |
26 ms |
364 KB |
Output is correct |
15 |
Correct |
26 ms |
364 KB |
Output is correct |
16 |
Correct |
26 ms |
364 KB |
Output is correct |
17 |
Correct |
26 ms |
364 KB |
Output is correct |
18 |
Correct |
53 ms |
364 KB |
Output is correct |
19 |
Correct |
53 ms |
396 KB |
Output is correct |
20 |
Correct |
103 ms |
492 KB |
Output is correct |
21 |
Correct |
103 ms |
492 KB |
Output is correct |
22 |
Correct |
104 ms |
364 KB |
Output is correct |
23 |
Correct |
104 ms |
512 KB |
Output is correct |