http://acm.hdu.edu.cn/showproblem.php?pid=4696

由题意可知 1<=Ci<=2 而且图上一定有环

那么我们可以得出:

只要存在奇环(即Ci=1)..那么对于所有自然数Mi都能得到

否则就是偶环 只有Mi是偶数才能得到

/********************* Template ************************/
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std; #define EPS 1e-8
#define MAXN 100005
#define MOD (int)1e9+7
#define PI acos(-1.0)
#define DINF (1e10)
#define LINF ((1LL)<<50)
#define INF (0x3f3f3f3f)
#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) < (b) ? (a) : (b))
#define max3(a,b,c) (max(max(a,b),c))
#define min3(a,b,c) (min(min(a,b),c))
#define BUG cout<<"BUG! "<<endl
#define line cout<<"--------------"<<endl
#define L(t) (t << 1)
#define R(t) (t << 1 | 1)
#define Mid(a,b) ((a + b) >> 1)
#define lowbit(a) (a & -a)
#define FIN freopen("in.txt","r",stdin)
#define FOUT freopen("out.txt","w",stdout)
#pragma comment (linker,"/STACK:102400000,102400000") // typedef long long LL;
// typedef unsigned long long ULL;
// typedef __int64 LL;
// typedef unisigned __int64 ULL;
// LL gcd(LL a,LL b){ return b?gcd(b,a%b):a; }
// LL lcm(LL a,LL b){ return a*b/gcd(a,b); } /********************* F ************************/
int to[MAXN];
bool vis[MAXN];
int val[MAXN];
int main()
{
//FIN;
//FOUT;
int n,Q,c;
while(~scanf("%d%d",&n,&Q)){
memset(vis,false,sizeof(vis));
for(int i = ; i <= n ; i++)
scanf("%d",&to[i]);
for(int i = ; i <= n ; i++)
scanf("%d",&val[i]);
bool odd_cir = false;
for(int i = ; i <= n && !vis[i] ; i++){
if(val[i] == ){
int res = ;
for(int j = i ;; j = to[j]){
res += val[i];
vis[j] = true;
if(vis[to[j]] == true) {
odd_cir = true;
break;
}
}
if(odd_cir == true) break;
}
}
for(int i = ; i < Q ; i++){
scanf("%d",&c);
if(c <= ) puts("NO");
else {
if(odd_cir == true)
puts("YES");
else{
if(c % == ) puts("YES");
else puts("NO");
}
}
}
}
return ;
}

HDU 4696 Answers 水题的更多相关文章

  1. hdu 5210 delete 水题

    Delete Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5210 D ...

  2. hdu 1251 (Trie水题)

    统计难题 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131070/65535 K (Java/Others)Total Submi ...

  3. HDU 4696 Answers (2013多校10,1001题 )

    Answers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total S ...

  4. HDU 5703 Desert 水题 找规律

    已知有n个单位的水,问有几种方式把这些水喝完,每天至少喝1个单位的水,而且每天喝的水的单位为整数.看上去挺复杂要跑循环,但其实上,列举几种情况之后就会发现是找规律的题了= =都是2的n-1次方,而且这 ...

  5. HDU 4493 Tutor 水题的收获。。

    题目: http://acm.hdu.edu.cn/showproblem.php?pid=4493 题意我都不好意思说,就是求12个数的平均数... 但是之所以发博客,显然有值得发的... 这个题最 ...

  6. hdu 4802 GPA 水题

    GPA Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4802 Des ...

  7. hdu 4493 Tutor 水题

    Tutor Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4493 D ...

  8. hdu 5495 LCS 水题

    LCS Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5495 Descr ...

  9. hdu 4891 模拟水题

    http://acm.hdu.edu.cn/showproblem.php?pid=4891 给出一个文本,问说有多少种理解方式. 1. $$中间的,(s1+1) * (s2+1) * ...*(sn ...

随机推荐

  1. webpack的理解

    webpack是一个模块打包工具,你可以使用webpack管理你的模块依赖,并编译输出模块们所需要的静态文件.它能够很好的管理.打包Web开发中所用到的HTML.Javascript.CSS以及各种静 ...

  2. [NOIP2015提高组]子串

    题目:洛谷P2679.Vijos P1982.codevs4560.UOJ#149. 题目大意:有长度为n的A串和长度为m的B串.现在要从A串中取出k个互不重叠的子串,使它们按顺序相连后得到B串.问有 ...

  3. 阿里云上如何找到虚拟主机和用户名登录FileZilla软件?

    0.少玩游戏 1.登录阿里云官网 :https://www.aliyun.com/ 2.点击自己的旁边的名称进入进入自己的页面 3.购买的域名和主机会在这里显示,点击域名与网站(万网)>云虚拟主 ...

  4. caioj 1077 动态规划入门(非常规DP1:筷子)

    首先可以看出排序之后,最优解肯定是每一对都相邻才是最优的 那么我们就要找构成最优解的相邻组 设f[i][j]是前i个字符,k对的最小值 如果当前这个筷子不取的话,f[i][j] = f[i-1][j] ...

  5. iOS-入门HelloWorld

    刚刚搞了几个图形界面的iOS应用程序,难的没搞定一个,HelloWorld程序倒是很简单. 新建Project,iOS->Application->Single View Applicat ...

  6. C++调用Lua的性能測试

    游戏服务器经典的架构就是C++和Lua的结合,C++开发主体框架.Lua实现一些复杂的逻辑.我们都知道Lua是一种很快的语言.可是究竟有多块.我们測试下看看. C++调用Lua的性能測试.发现不正确的 ...

  7. [Python] Pandas load DataFrames

    Create an empty Data frame with date index: import pandas as pd def test_run(): start_date='2017-11- ...

  8. Shell脚本中替换字符串等操作

    在做shell批处理程序时候,常常会涉及到字符串相关操作. 有非常多命令语句.如:awk,sed都能够做字符串各种操作. 事实上shell内置一系列操作符号.能够达到类似效果,大家知道,使用内部操作符 ...

  9. xml里面product的值在哪里设置的?

    转载请注明出处:http://blog.csdn.net/droyon/article/details/39890469 在进行Android应用程序开发时,善于运用xml中的product配置,能够 ...

  10. 两个对象值同样(x.equals(y) == true),但却可有不同的hash code,这句话对不正确?

    1.网上面试题 这是一道Java面试题.看了非常多答案都说不正确.能够看下面代码.就知道结果了 http://www.iteye.com/topic/485046第45题 答案是错误的 package ...