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. Java ——代理模式[转发]

    1.  简介 代理模式(Proxy Pattern)是GoF 23种Java常用设计模式之一.代理模式的定义:Provide a surrogate or placeholder for anothe ...

  2. python读取word文档

    周末需要做一个统计word文档字数的问题,刚开始以为很简单,因为之前做过excel表格相关的任务,所以认为利用扩展模块应该比较简单. 通过搜索,确实搜到了一个python操作word的模块,pytho ...

  3. NodeJS学习笔记 (20)错误处理-error

    文章地址 https://github.com/chyingp/nodejs-learning-guide

  4. iOS开发——根据数组中的字典中的某一元素排序

    数组中的元素是字典,字典中的某一个元素,比如说姓名,现在需要按照姓名的首字母来排序,怎么搞? 做法很简单,在字典中加一个元素,保存姓名的首字母,然后用下面的方法排序. - (void)sortWifi ...

  5. Win 7系统倒计时!

    3月25日消息,近日微软已经开始通知当前正在使用Windows 7的用户,该操作系统“接近尾声”.微软表示计划在2020年1月14日终止对Windows 7的所有支持.但结束Windows 7似乎并不 ...

  6. ruby redis的集群管理器

    #========================================================================================== # => ...

  7. 基于express+redis高速实现实时在线用户数统计

    作者:zhanhailiang 日期:2014-11-09 本文将介绍怎样基于express+redis高速实现实时在线用户数统计. 1. 在github.com上创建项目uv-tj.将其同步到本地: ...

  8. QThread 爬坑之旅(三种办法解决QObject: Cannot create children for a parent that is in a different thread)

    Cannot create children for a parent that is in a different thread. 在Qt的官方文档,大家知道有两种方式使用QThread. You ...

  9. css如何实现垂直居中(5种方法)

    css如何实现垂直居中(5种方法) 一.总结 一句话总结:行内只需要简单地把 line-height 设置为那个对象的 height 值就可以使文本居中了. 块的话可以尝试 margin:auto: ...

  10. Centos7 网络出错(failed to start LSB: Bring up/down networking )

    这是我更换了VM虚拟机内存,重启后无法连接网络. 然后这是因为NetworkManager.service这个程序造成 解决方法: systemctl disable NetworkManager.s ...