题目:http://acm.hdu.edu.cn/showproblem.php?pid=4696
题目大意:给你一个图,每个点的出度都为1,每个点的权值为1或2,然后问你能不能找到一条路径的权值和为 M。
思路:图中必定有环,那么 如果C中有1,那么就能构成任何数,如果不存在1,那么只能构成偶数。
想不到这样就好了,太坑了。。
代码如下:
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
int n,q;
while(~scanf("%d%d",&n,&q))
{
int x;
for(int i = 1;i<=n;i++)
scanf("%d",&x);
int flag = 0;
for(int i = 1;i<=n;i++)
{
scanf("%d",&x);
if(x == 1)
flag = 1;
}
for(int i = 1;i<=q;i++)
{
scanf("%d",&x);
if(x <= 0)
{
puts("NO");
continue;
}
if(flag)
puts("YES");
else
{
if(x&1) puts("NO");
else puts("YES");
}
}
}
return 0;
}