GT and set
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
You should divide the sets into L parts.
And each part should have at least one number in common.
If there is at least one solution,print YES,otherwise print NO.
For each teatcase:
In the first line there are two numbers N and L.
In the next N lines,each line describe a set.
The first number is Ai,and then there are Ai distict numbers stand for the elements int the set.
The numbers in the set are all positive numbers and they're all not bigger than 300.
1≤N≤30,1≤L≤5,1≤Ai≤10,1≤L≤N
You'd better print the enter in the last line when you hack others.
You'd better not print space in the last of each line when you hack others.
For the second test,there are three sets:{1,2,3},{4,5,6},{2,5,6} You are asked to divide into two parts. One possible solution is to put the second and the third sets into the same part,and put the first in the other part. The second part and the third part have same number 6. Another solution is to put the first and the third sets into the same part,and put the second in the other part.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
#define eps 1e-14
const int N=2e5+,M=1e6+,inf=1e9+;
const ll INF=1e18+,mod=;
bitset<> flag[],a[],temp,bit;
int n,m,ans;
void dfs(int pos)
{
if(pos>n||ans)
{
ans=;
return;
}
for(int i=;i<=m;i++)
{
temp=flag[i]&a[pos];
bit=flag[i];
if(temp.count())
{
flag[i]=temp;
dfs(pos+);
flag[i]=bit;
}
}
}
void init()
{
for(int i=;i<=n;i++)
a[i].reset();
for(int i=;i<=m;i++)
flag[i].set();
ans=;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
init();
for(int i=;i<=n;i++)
{
int z;
scanf("%d",&z);
for(int j=;j<=z;j++)
{
int x;
scanf("%d",&x);
a[i].set(x);
}
}
dfs();
if(ans)
printf("YES\n");
else
printf("NO\n");
}
return ;
}