【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的更多相关文章

  1. 【数位dp】【HDU 3555】【HDU 2089】数位DP入门题

    [HDU  3555]原题直通车: 代码: // 31MS 900K 909 B G++ #include<iostream> #include<cstdio> #includ ...

  2. 【HDU 5647】DZY Loves Connecting(树DP)

    pid=5647">[HDU 5647]DZY Loves Connecting(树DP) DZY Loves Connecting Time Limit: 4000/2000 MS ...

  3. -【线性基】【BZOJ 2460】【BZOJ 2115】【HDU 3949】

    [把三道我做过的线性基题目放在一起总结一下,代码都挺简单,主要就是贪心思想和异或的高斯消元] [然后把网上的讲解归纳一下] 1.线性基: 若干数的线性基是一组数a1,a2,a3...an,其中ax的最 ...

  4. 【HDU 2196】 Computer(树的直径)

    [HDU 2196] Computer(树的直径) 题链http://acm.hdu.edu.cn/showproblem.php?pid=2196 这题可以用树形DP解决,自然也可以用最直观的方法解 ...

  5. 【HDU 2196】 Computer (树形DP)

    [HDU 2196] Computer 题链http://acm.hdu.edu.cn/showproblem.php?pid=2196 刘汝佳<算法竞赛入门经典>P282页留下了这个问题 ...

  6. 【HDU 5145】 NPY and girls(组合+莫队)

    pid=5145">[HDU 5145] NPY and girls(组合+莫队) NPY and girls Time Limit: 8000/4000 MS (Java/Other ...

  7. 【hdu 1043】Eight

    [题目链接]:http://acm.hdu.edu.cn/showproblem.php?pid=1043 [题意] 会给你很多组数据; 让你输出这组数据到目标状态的具体步骤; [题解] 从12345 ...

  8. 【HDU 3068】 最长回文

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=3068 [算法] Manacher算法求最长回文子串 [代码] #include<bits/s ...

  9. 【HDU 4699】 Editor

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=4699 [算法] 维护两个栈,一个栈放光标之前的数,另外一个放光标之后的数 在维护栈的同时求最大前缀 ...

随机推荐

  1. Qt中事件分发源码剖析

    Qt中事件分发源码剖析 Qt中事件传递顺序: 在一个应该程序中,会进入一个事件循环,接受系统产生的事件,而且进行分发,这些都是在exec中进行的. 以下举例说明: 1)首先看看以下一段演示样例代码: ...

  2. .vscode folder

    https://stackoverflow.com/questions/32964920/should-i-commit-the-vscode-folder-to-source-control Che ...

  3. 智课雅思词汇---七、cur是什么意思

    智课雅思词汇---七.cur是什么意思 一.总结 一句话总结:词根:cur, curs ( cor, cour, cours, coars) = to run 1.cub是什么意思? 词根:cumb, ...

  4. 19.volatile

    volatile 编译器会自动优化,而volatile起到的作用是禁止优化,每次读内存

  5. Codeforces Round #206 (Div. 2) 部分题解

    传送门:http://codeforces.com/contest/355 A:水题,特判0 int k,d; int main(){ //FIN; while(cin>>k>> ...

  6. flex 光标(CursorManager)

    flex 光标(CursorManager)  CursorManager相关属性   getInstance():ICursorManager AIR 应用程序中的每个 mx.core.Window ...

  7. Dcloud+mui 压缩上传图片到服务器

    chooseImgFromAlbums选择图片 chooseImgFromPictures 拍照 changeToLocalUrl 转换成可用的路径 uploadpic.compressImg 压缩图 ...

  8. 利用js 获取ip和地址

    1.引用第三方js<script src="http://pv.sohu.com/cityjson?ie=utf-8"></script> 2.     I ...

  9. NOIP 模拟赛

    NOIP 模拟赛 思路:求 n , m 的 gcd,然后用 n , m 分别除以 gcd:若 n 或 m 为偶数,则输出 1/2. 特别的,当 n = m = 1 时,应输出 1/1 #include ...

  10. Spring MVC学习总结(5)——SpringMVC项目关于安全的一些配置与实现方式

    目前越来越多的应用和网站,开始注重安全性的问题,关于我们的web项目的几个安全知识点,不得不讲解一下,这里我主要讲述关于tomcat如何支持HTTPS连接访问,RSA公钥和私钥的制作.这个对于我们整个 ...