dfs染色法判定二分图
#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染色法判定二分图的更多相关文章
- AcWing 860. 染色法判定二分图
#include <cstring> #include <iostream> #include <algorithm> using namespace std; , ...
- bfs染色法判定二分图
#include<iostream> #include<queue> #include<cstring> #include<cstdio> using ...
- hdu 2444(染色法判断二分图+最大匹配)
The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- 【交叉染色法判断二分图】Claw Decomposition UVA - 11396
题目链接:https://cn.vjudge.net/contest/209473#problem/C 先谈一下二分图相关: 一个图是二分图的充分必要条件: 该图对应无向图的所有回路必定是偶环(构成该 ...
- poj 2942 求点双联通+二分图判断奇偶环+交叉染色法判断二分图
http://blog.csdn.net/lyy289065406/article/details/6756821 http://www.cnblogs.com/wuyiqi/archive/2011 ...
- 染色法判断是否是二分图 hdu2444
用染色法判断二分图是这样进行的,随便选择一个点, 1.把它染成黑色,然后将它相邻的点染成白色,然后入队列 2.出队列,与这个点相邻的点染成相反的颜色 根据二分图的特性,相同集合内的点颜色是相同的,即 ...
- hdu 4751 Divide Groups(dfs染色 或 2-sat)
Problem Description This year is the 60th anniversary of NJUST, and to make the celebration more c ...
- DFS的运用(二分图判定、无向图的割顶和桥,双连通分量,有向图的强连通分量)
一.dfs框架: vector<int>G[maxn]; //存图 int vis[maxn]; //节点访问标记 void dfs(int u) { vis[u] = ; PREVISI ...
- Wrestling Match---hdu5971(2016CCPC大连 染色法判断是否是二分图)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5971 题意:有n个人,编号为1-n, 已知X个人是good,Y个人是bad,m场比赛,每场比赛都有一个 ...
随机推荐
- UVaLive 2965 Jurassic Remains (状态压缩)
题意:给定 n 个大写字母组成的字符串,选择尽量多的串,使得大写字母都能出现偶数次. 析:由于n比较小,我们可以枚举前n/2的所有组合,然后再从后面查找. 代码如下: #pragma comment( ...
- POJ - 3414 Pots BFS(著名倒水问题升级版)
Pots You are given two pots, having the volume of A and B liters respectively. The following operati ...
- LeetCode: 292 Nim Game(easy)
题目: You are playing the following Nim Game with your friend: There is a heap of stones on the table, ...
- HDU5971【瞎搞】
题意:略(忙着准备文化课...明天期中考啊.... 思路: 正解就是染色,2-sat搞: AC代码(虽然是错误的...数据水(过踏马的也行啊,起码打脸他啊!) 4 3 1 0 1 2 2 3 3 4 ...
- Unity IK(反向运动学)初探
http://blog.csdn.net/myarrow/article/details/44450199 1. 简介 IK与FK对应,正向运动学就是根骨骼带动节点骨骼运动.而反向运动学就是反过来,由 ...
- js框架:jQuery
· jQuery是一个轻量级的“写的少,做的多”的JavaScript函数库(jQuery版本2以上不支持IE6,7,8) · jQuery 的功能概括: 1.html 的元素选取 2.html的元素 ...
- css 文本显示多行后用省略号显示剩余的
display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 5; overflow: hidden;
- hibernate错误总结1
- IP服务-1-ARP和代理ARP
代理ARP常被人忽视,因为现在基本不用了
- 字典树(POJ 2503)
它的优点是:利用字符串的公共前缀来减少查询时间,最大限度地减少无谓的字符串比较,查询效率比哈希树高. 它有3个基本性质: 根节点不包含字符,除根节点外每一个节点都只包含一个字符: 从根节点到某一节点, ...