#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. Codeforces Round #375 (Div. 2)【A,B【模拟】,D【DFS】】

    PS_B:阿洗吧!B题卧槽数组开了250... PS_D:D题主要挂在了50*50口算得了250,数组开小,然后一开始还错了.= =哎,以后对于数据范围还是注意一点: 卧槽,这场可真二百五了... A ...

  2. android调用其他apk的activity

    <img src="https://img-blog.csdn.net/20160322114625025" alt="" />启动另一个apk的工 ...

  3. 进击python第三篇:基础

    基础拾遗 序列解包 例: >>>x,y,z=1,2,3 >>>print x,y,z 1 2 3 交换变量也是没问题 >>>x,y=y,x > ...

  4. 实现easyui combobox中textField字段的拼接

    开发过程中遇到这样的一个需求: 从后台得到的两个字段aa.bb拼接为一个字段aabb显示在easyui combobx的下拉选项中. 实现方法: 利用formatter属性定义如何呈现行: 页面代码: ...

  5. assembly x86(nasm)修改后的日常

    data segment ENG db 'SUNdayS Coming I Wanna Drive My Car,SUN,SUN$' ;9,3 sun1 db 'SUN' swcount db 0ah ...

  6. iOS 7:漫谈#define 宏定义(转)

    iOS :漫谈#define 宏定义 #define宏定义在C系开发中可以说占有举足轻重的作用.底层框架自不必说,为了编译优化和方便,以及跨平台能力,宏被大量使用,可以说底层开发离开define将寸步 ...

  7. 字符条件变成in条件格式数据

    private string getInQuerySql(string query) { string resulr = ""; foreach (var item in quer ...

  8. PostgreSQL-6-数据分组

    基本语法 SELECT column-list FROM table_name WHERE [ conditions ] GROUP BY column1, column2 HAVING [ cond ...

  9. C# 常量与只读属性的区别

    public readonly string name ----这个name是个只读属性,不需要在定义时初始化值,而是可以在构造函数中完成初始化. public const int age =18   ...

  10. jQuery插件pagination.js源码解读

    pagination的github地址:https://github.com/gbirke/jquery_pagination 公司用的是1.2的版本,所以我就读1.2的了. jQuery.fn.pa ...