#include<iostream>
#include<cstring>
using namespace std;
int mapp[][],color[],n;
int dfs(int x,int c)
{
color[x]=c;
for(int i=;i<=n;i++)
{
if(mapp[x][i]==)
{
if(color[i]==c)
return ;
if(color[i]==&&!dfs(i,-c))
return ;
}
}
return ;
}
int main()
{
int T,m,x,flag,y,g;
cin>>T;
while(T--)
{
cin>>n>>m;
memset(mapp,,sizeof(mapp));
memset(color,,sizeof(color));
for(int i=;i<=m;i++)
{
cin>>x>>y;
mapp[x][y]=;
mapp[y][x]=;
}
flag=;
for(int i=;i<=n;i++)
{
if(color[i]==&&!dfs(i,))
{
flag=;
break;
}
}
if(flag==)
{
cout<<"No"<<endl;
}
else
{
cout<<"Yes"<<endl;
}
}
}

dfs染色法判定二分图的更多相关文章

  1. AcWing 860. 染色法判定二分图

    #include <cstring> #include <iostream> #include <algorithm> using namespace std; , ...

  2. bfs染色法判定二分图

    #include<iostream> #include<queue> #include<cstring> #include<cstdio> using ...

  3. hdu 2444(染色法判断二分图+最大匹配)

    The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

  4. 【交叉染色法判断二分图】Claw Decomposition UVA - 11396

    题目链接:https://cn.vjudge.net/contest/209473#problem/C 先谈一下二分图相关: 一个图是二分图的充分必要条件: 该图对应无向图的所有回路必定是偶环(构成该 ...

  5. poj 2942 求点双联通+二分图判断奇偶环+交叉染色法判断二分图

    http://blog.csdn.net/lyy289065406/article/details/6756821 http://www.cnblogs.com/wuyiqi/archive/2011 ...

  6. 染色法判断是否是二分图 hdu2444

    用染色法判断二分图是这样进行的,随便选择一个点, 1.把它染成黑色,然后将它相邻的点染成白色,然后入队列 2.出队列,与这个点相邻的点染成相反的颜色 根据二分图的特性,相同集合内的点颜色是相同的,即 ...

  7. hdu 4751 Divide Groups(dfs染色 或 2-sat)

    Problem Description   This year is the 60th anniversary of NJUST, and to make the celebration more c ...

  8. DFS的运用(二分图判定、无向图的割顶和桥,双连通分量,有向图的强连通分量)

    一.dfs框架: vector<int>G[maxn]; //存图 int vis[maxn]; //节点访问标记 void dfs(int u) { vis[u] = ; PREVISI ...

  9. Wrestling Match---hdu5971(2016CCPC大连 染色法判断是否是二分图)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5971 题意:有n个人,编号为1-n, 已知X个人是good,Y个人是bad,m场比赛,每场比赛都有一个 ...

随机推荐

  1. POJ 3662 Telephone Lines (二分+dijkstra)

    题意: 多年以后,笨笨长大了,成为了电话线布置师.由于地震使得某市的电话线全部损坏,笨笨是负责接到震中市的负责人. 该市周围分布着N(1<=N<=1000)根据1……n顺序编号的废弃的电话 ...

  2. D3.js(v3)+react 制作 一个带坐标轴与比例尺的折线图

    本章使用路径生成器来绘制一个折线图.以中国和日本的GDP数据为例:   //数据 var dataList = [ { coountry : "china", gdp : [ [2 ...

  3. (水题)洛谷 - P2439 - 阶梯教室设备利用 - 简单dp

    https://www.luogu.org/fe/problem/P2439 很明显时间是一个维度,按照时间顺序决策就行了. dp[i]表示以时间i为结尾所能达到的最长演讲时间. #include & ...

  4. 解决 unity 生成 android apk read Resources

    http://www.cnblogs.com/solq/archive/2012/05/21/2511522.html TextAsset t = (TextAsset)Resources.Load( ...

  5. [Xcode 实际操作]一、博主领进门-(5)检测运行中的模拟器在各个方向上的切换

    目录:[Swift]Xcode实际操作 本文将演示Xcode的设备模拟器在各个方向上的切换和检测. 在项目导航区,打开视图控制器的代码文件[ViewController.swift] 检测运行中的模拟 ...

  6. Proteomes of paired human cerebrospinal fluid and plasma: Relation to blood-brain barrier permeability in older adults (文献分享一组-潘火珍)

    题目:Proteomes of paired human cerebrospinal fluid and plasma: Relation to blood-brain barrier permeab ...

  7. python 的 数据类型

    数据类型 1.1整型int py2中有int有范围,超出自动转为long长整型,py3中只有int 整除py2中无小数,可加一行代码实现 十进制转二进制 print(bin(10))十进制转八进制 p ...

  8. 未能载入软件包“WebDriverAgentRunner”,因为它已损坏或丢失必要的资源。

    添加 YYCache.framework RoutingHTTPServer.framework

  9. python 基础(十五) socket编程

    SOCKET TCP协议: 有请求 有响应 称之为 tcp协议 是面向连接的协议 就是在收发数据之前 必须先要建立一个可靠的链接 三次握手 如:网站 UDP协议: 是一个非链接的协议 传输之前不需要键 ...

  10. EM算法(徐亦达)笔记