【hdu 3478】Catch
【Link】:http://acm.hdu.edu.cn/showproblem.php?pid=3478
【Description】
一个人从起点s出发,假设他在时间t在节点x;
则在时间t+1,他能到达x-y-z这条路径的z节点上;
也即越过一个节点.到达下一个点.
且只能这样走;
问他能不能走遍所有的点.
【Solution】
如果图是不联通的。那么肯定走不遍。
是联通的话,
如果是一张二分图的话.
这样的走法只能从二分图的左半部分点之间走来走去;
永远走不到右边的点;
而只要在二分图的左半部分的任意两个点之间加那么一条的边.
就发现可以走到右半部分了;
然后再用二分图的规则走遍右半部分就可以了;
这样加一条边,如果更直观一点,也就是说它不是一个二分图的时候.
综上:
只要这张联通图不是二分图,就是YES,否则NO;
如果不连通输出no
【NumberOf WA】
0
【Reviw】
模型转化
【Code】
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define ri(x) scanf("%d",&x)
#define rl(x) scanf("%lld",&x)
#define rs(x) scanf("%s",x+1)
#define oi(x) printf("%d",x)
#define ol(x) printf("%lld",x)
#define oc putchar(' ')
#define os(x) printf(x)
#define all(x) x.begin(),x.end()
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0)
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 1e5;
int n,m,s,f[N+100],color[N+100];
vector <int> g[N+100];
int ff(int x){
if (f[x] == x) return x;
else
return f[x] = ff(f[x]);
}
void hebing(int x,int y){
int r1 = ff(x),r2 = ff(y);
if (r1!=r2) f[r1] = r2;
}
int dfs(int x,int c){
color[x] = c;
int len = g[x].size();
int bo = 1;
rep1(i,0,len-1){
int y = g[x][i];
if (color[y]==-1)
bo &= dfs(y,1-c);
else
if (color[y]==color[x]) return 0;
}
return bo;
}
int main(){
//Open();
//Close();
int T,kk = 0;
ri(T);
while (T--){
rep1(i,1,N) g[i].clear();
ri(n),ri(m),ri(s);s++;
rep1(i,1,n) f[i] = i;
rep1(i,1,m){
int x,y;
ri(x),ri(y);
x++,y++;
g[x].pb(y),g[y].pb(x);
hebing(x,y);
}
bool ok = true;
int s = ff(1);
rep1(i,2,n)
if (ff(i)!=s)
ok = false;
if (!ok) {
os("Case ");oi(++kk);puts(": NO");
continue;
}
ms(color,255);
if (dfs(1,0)){
os("Case ");oi(++kk);puts(": NO");
}else{
os("Case ");oi(++kk);puts(": YES");
}
}
return 0;
}
【hdu 3478】Catch的更多相关文章
- 【数位dp】【HDU 3555】【HDU 2089】数位DP入门题
[HDU 3555]原题直通车: 代码: // 31MS 900K 909 B G++ #include<iostream> #include<cstdio> #includ ...
- 【HDU 5647】DZY Loves Connecting(树DP)
pid=5647">[HDU 5647]DZY Loves Connecting(树DP) DZY Loves Connecting Time Limit: 4000/2000 MS ...
- -【线性基】【BZOJ 2460】【BZOJ 2115】【HDU 3949】
[把三道我做过的线性基题目放在一起总结一下,代码都挺简单,主要就是贪心思想和异或的高斯消元] [然后把网上的讲解归纳一下] 1.线性基: 若干数的线性基是一组数a1,a2,a3...an,其中ax的最 ...
- 【HDU 2196】 Computer(树的直径)
[HDU 2196] Computer(树的直径) 题链http://acm.hdu.edu.cn/showproblem.php?pid=2196 这题可以用树形DP解决,自然也可以用最直观的方法解 ...
- 【HDU 2196】 Computer (树形DP)
[HDU 2196] Computer 题链http://acm.hdu.edu.cn/showproblem.php?pid=2196 刘汝佳<算法竞赛入门经典>P282页留下了这个问题 ...
- 【HDU 5145】 NPY and girls(组合+莫队)
pid=5145">[HDU 5145] NPY and girls(组合+莫队) NPY and girls Time Limit: 8000/4000 MS (Java/Other ...
- 【hdu 1043】Eight
[题目链接]:http://acm.hdu.edu.cn/showproblem.php?pid=1043 [题意] 会给你很多组数据; 让你输出这组数据到目标状态的具体步骤; [题解] 从12345 ...
- 【HDU 3068】 最长回文
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=3068 [算法] Manacher算法求最长回文子串 [代码] #include<bits/s ...
- 【HDU 4699】 Editor
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=4699 [算法] 维护两个栈,一个栈放光标之前的数,另外一个放光标之后的数 在维护栈的同时求最大前缀 ...
随机推荐
- PPAPI中使用Chromium的3D图形接口
使用PPAPI的Graphics 3D接口做了一个小演示样例,鼠标点击插件区域.绘制颜色,效果与ppapi_simple相似. foruok原创,如需转载请关注foruok的微信订阅号"程序 ...
- 2015上海网络赛 HDU 5478 Can you find it 数学
HDU 5478 Can you find it 题意略. 思路:先求出n = 1 时候满足条件的(a,b), 最多只有20W对,然后对每一对进行循环节判断即可 #include <iostre ...
- 分享一下vue ui的分页的用法
var newToAddLeave = function(){ var goIndex = { template:` <i-table :columns="overTimeList.c ...
- Codefroces B. Hamming Distance Sum
Genos needs your help. He was asked to solve the following programming problem by Saitama: The lengt ...
- installp 操作
installp 软件安装和升级工具 1.查看某个已应用更可被提交或拒绝的文件集) installp -s 2. 应用更新TCP/IP软件( /usr/sys/inst.images ) ...
- U-BOOT概述及源码分析(一)
嵌入式Linux系统从软件角度通常可以分为以下4个层次: 引导加载程序 | Linux内核 | 文件系统 | 用户应用程序 嵌入式Linux系统中典型分区结构: 正常启动过程中,Bootloader首 ...
- 云计算时代告别phpMyAdmin
云计算时代告别phpMyAdmin phpMyAdmin是一款很经典的MySQL数据库管理工具,在云计算快速发展的今天,phpMyAdmin交互老旧.已经不能适应时代步伐.因此有很多人開始选择一些更高 ...
- 【原生JS组件】javascript 运动框架
大家都知道JQuerry有animate方法来给DOM元素进行运动,CSS3中也有transition.transform来进行运动.而使用原生的Javascript来控制元素运动,须要写非常多运动的 ...
- 转战Androidstudio之项目eclipse迁移
新项目開始,决定转战as战场,(是应为听说了太多关于as的夸赞我才来的),期间各种不爽不适应历历在目啊.闲话少说,项目迁移開始 1.Eclipse迁出 当然直接从Eclipse迁出是有条件的,ADT必 ...
- J2SE基础:2.对象的创建与使用
1:參数传递的值传递与引用传递 A:值传递:基本数据类型传递都是值传递 B:引用传递(地址传递):对象数据类型都是引用传递. 2:类变量与成员变量(实例变量,对象变量) 类变量:通过类名调用,类变量被 ...