记录编号 45295 评测结果 AAAAAAAAAA
题目名称 [WZOI 2011 S3] 食物中毒 最终得分 100
用户昵称 Gravatar苏轼 是否通过 通过
代码语言 C++ 运行时间 0.503 s
提交时间 2012-10-23 10:13:26 内存使用 2.83 MiB
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;
int n,m,tmp,answer;
unsigned long long ww=0,w[100]={0},q[60]={0};
void dfs(unsigned long long x,unsigned long long y);
int main()
{
	freopen ("medicine.in","r",stdin);
	freopen ("medicine.out","w",stdout);
	while (cin>>n>>m)
	{
		answer=0;
		ww=0;
		for (int i=0;i<=60;i++)
		{
			w[i]=0;
		}
		for (int i=0;i<m;i++)
		{
			cin>>tmp;
			ww+=(1ll<<(tmp-1));
		}
		for (int i=1;i<=n;i++)
		{
			int temp;
			cin>>temp;
			for (int j=0;j<temp;j++)
			{
				cin>>tmp;
				w[i]=w[i]^(1ll<<(tmp-1));
			}
		}
		dfs(1,0);
		if (answer)
		{
			cout<<"Possible"<<endl;
		}
		else
		{
			cout<<"Impossible"<<endl;
		}
	}
	return 0;
}
void dfs(unsigned long long x,unsigned long long y)
{
	if (x>n)
	{
		if ((y&ww)==ww)
			answer=1;
		return;
	}
	else
	{
		q[x]=1;
		dfs(x+1,y^w[x]);
		if (answer)
			return;
		q[x]=0;
		dfs(x+1,y);
		if (answer)
			return;
	}
}