显示代码纯文本
#include <cstdio>
#include <memory.h>
using namespace std;
long long n,tar,med[51];
bool done;
void make(int deep,bool get,long long got)
{
if (deep==n)
{
if (get)
got=got^med[deep];
if (((~got)&tar)==0)
done=true;
}
else
{
if (get)
{
make(deep+1,0,got^med[deep]);
if (done)
return;
make(deep+1,1,got^med[deep]);
}
else
{
make(deep+1,0,got);
if (done)
return;
make(deep+1,1,got);
}
}
}
int main(void)
{
freopen("medicine.in","r",stdin);
freopen("medicine.out","w",stdout);
long long squ[51]={1};
int i,j,m,x,y;
for (i=1;i<=50;i++)
squ[i]=squ[i-1]<<1;
while (scanf("%d%d",&n,&m)==2)
{
done=false;
tar=0;
memset(med,0,sizeof(med));
for (i=1;i<=m;i++)
{
scanf("%d",&x);
tar+=squ[x];
}
for (i=1;i<=n;i++)
{
scanf("%d",&x);
for (j=1;j<=x;j++)
{
scanf("%d",&y);
med[i]=med[i]^squ[y];
}
}
make(1,0,0);
if (!done)
make(1,1,0);
if (done)
printf("Possible\n");
else
printf("Impossible\n");
}
return(0);
}