#include <bits/stdc++.h>
using namespace std;
typedef long long lo;
typedef pair< lo,lo > PII;
#define fi first
#define se second
#define int long long
#define mp make_pair
#define endl "\n"
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)
const lo inf = 1000000000000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 65;
const lo mod = 1000000007;
int n,m,b[li],a[li][li],k,flag,t,no[li],l[li],comp;
int cev;
string s;
map<int,vector<int>> vec;
map<int,int> okk;
vector<int> mini;
inline void f(int sira,int mask){
if(sira>=m/2){
for(int i=1;i<=n;i++)no[i]=0;
for(int i=0;i<m;i++){
if((mask&(1ll<<i))==0)continue;
for(int j=1;j<=l[i];j++){
no[a[i][j]]++;
}
}
flag=0;
FOR{
if(no[i]%2==0)flag=1;
}
vector<int> v;
//~ if(flag==1)return ;
for(int i=0;i<m;i++){
if((mask&(1ll<<i))==0)continue;
v.pb(i+1);
}
if(flag==0){
//~ cout<<"**\n";
if((int)mini.size()==0)swap(mini,v);
else if((int)mini.size()>(int)v.size())swap(mini,v);
else if((int)mini.size()==(int)v.size() && v<mini)swap(mini,v);
return ;
}
int maski=0;
FOR{
if(no[i]%2)maski=(maski|(1ll<<i));
}
//~ cout<<"**"<<maski<<"**\n";
okk[maski]=1;
if((int)vec[maski].size()==0)swap(vec[maski],v);
else if((int)vec[maski].size()>(int)v.size())swap(vec[maski],v);
else if((int)vec[maski].size()==(int)v.size() && v<vec[maski])swap(vec[maski],v);
return ;
}
f(sira+1,mask);
f(sira+1,(mask|(1ll<<sira)));
}
inline void f1(int sira,int mask){
if(sira>=m){
for(int i=1;i<=n;i++)no[i]=0;
for(int i=0;i<m;i++){
if((mask&(1ll<<i))==0)continue;
for(int j=1;j<=l[i];j++){
no[a[i][j]]++;
}
}
flag=0;
FOR{
if(no[i]%2==0)flag=1;
}
vector<int> v;
//~ if(flag==1)return ;
for(int i=0;i<m;i++){
if((mask&(1ll<<i))==0)continue;
v.pb(i+1);
}
if(flag==0){
//~ cout<<"**\n";
if((int)mini.size()==0)swap(mini,v);
else if((int)mini.size()>(int)v.size())swap(mini,v);
else if((int)mini.size()==(int)v.size() && v<mini)swap(mini,v);
return ;
}
int maski=0;
FOR{
if(no[i]%2)maski=(maski|(1ll<<i));
}
int maski1=(comp^maski);
if(okk[maski1]==0)return ;
//~ cout<<"()"<<maski1<<"()"<<endl;
vector<int> vv;
for(int i=0;i<(int)vec[maski1].size();i++)vv.pb(vec[maski1][i]);
for(int i=0;i<(int)v.size();i++)vv.pb(v[i]);
if((int)mini.size()==0)swap(mini,vv);
else if((int)mini.size()>(int)vv.size())swap(mini,vv);
else if((int)mini.size()==(int)vv.size() && vv<mini)swap(mini,vv);
return ;
}
f1(sira+1,mask);
f1(sira+1,(mask|(1ll<<sira)));
}
main(void){
scanf("%lld %lld",&n,&m);
for(int i=1;i<=n;i++){
comp|=(1ll<<i);
}
for(int i=0;i<m;i++){
scanf("%lld",&l[i]);
for(int j=1;j<=l[i];j++)scanf("%lld",&a[i][j]);
}
f(0,0);
f1(m/2,0);
printf("%lld\n",(int)mini.size());
for(int i=0;i<(int)mini.size();i++){
printf("%lld ",mini[i]);
}
return 0;
}
Compilation message
norela.cpp:122:10: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main(void){
^
norela.cpp: In function 'int main()':
norela.cpp:123:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld %lld",&n,&m);
~~~~~^~~~~~~~~~~~~~~~~~~
norela.cpp:128:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld",&l[i]);
~~~~~^~~~~~~~~~~~~~
norela.cpp:129:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(int j=1;j<=l[i];j++)scanf("%lld",&a[i][j]);
~~~~~^~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
512 KB |
Output is correct |
2 |
Correct |
2 ms |
512 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
512 KB |
Output is correct |
2 |
Correct |
2 ms |
512 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
512 KB |
Output is correct |
7 |
Correct |
3 ms |
640 KB |
Output is correct |
8 |
Correct |
5 ms |
640 KB |
Output is correct |
9 |
Correct |
5 ms |
640 KB |
Output is correct |
10 |
Correct |
4 ms |
640 KB |
Output is correct |
11 |
Correct |
4 ms |
640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
512 KB |
Output is correct |
2 |
Correct |
2 ms |
512 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
512 KB |
Output is correct |
7 |
Correct |
3 ms |
640 KB |
Output is correct |
8 |
Correct |
5 ms |
640 KB |
Output is correct |
9 |
Correct |
5 ms |
640 KB |
Output is correct |
10 |
Correct |
4 ms |
640 KB |
Output is correct |
11 |
Correct |
4 ms |
640 KB |
Output is correct |
12 |
Correct |
5 ms |
640 KB |
Output is correct |
13 |
Correct |
7 ms |
896 KB |
Output is correct |
14 |
Correct |
7 ms |
896 KB |
Output is correct |
15 |
Correct |
7 ms |
896 KB |
Output is correct |
16 |
Correct |
9 ms |
896 KB |
Output is correct |
17 |
Correct |
8 ms |
896 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
512 KB |
Output is correct |
2 |
Correct |
2 ms |
512 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
512 KB |
Output is correct |
7 |
Correct |
3 ms |
640 KB |
Output is correct |
8 |
Correct |
5 ms |
640 KB |
Output is correct |
9 |
Correct |
5 ms |
640 KB |
Output is correct |
10 |
Correct |
4 ms |
640 KB |
Output is correct |
11 |
Correct |
4 ms |
640 KB |
Output is correct |
12 |
Correct |
5 ms |
640 KB |
Output is correct |
13 |
Correct |
7 ms |
896 KB |
Output is correct |
14 |
Correct |
7 ms |
896 KB |
Output is correct |
15 |
Correct |
7 ms |
896 KB |
Output is correct |
16 |
Correct |
9 ms |
896 KB |
Output is correct |
17 |
Correct |
8 ms |
896 KB |
Output is correct |
18 |
Correct |
11 ms |
1024 KB |
Output is correct |
19 |
Correct |
11 ms |
1024 KB |
Output is correct |
20 |
Correct |
14 ms |
1536 KB |
Output is correct |
21 |
Correct |
14 ms |
1536 KB |
Output is correct |
22 |
Correct |
14 ms |
1536 KB |
Output is correct |
23 |
Correct |
14 ms |
1536 KB |
Output is correct |