当前位置:网站首页>Determination of bipartite graph by coloring method
Determination of bipartite graph by coloring method
2022-04-22 03:48:00 【Bright autumn leaves】
Ideas
One : When a ring with odd edges is a graph, it is not a bipartite graph
Two : Dye all dots in two different colors , If it is a bipartite graph, the two colors must be evenly distributed
3、 ... and : Color conflict in the dyeing process is not a bipartite graph
Four : The connected next node of each node has the opposite color to that node
5、 ... and : If a node is not stained , Just dye him and all his connections

#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N=10e5+10,M=2*N;
int h[N],e[M],ne[M],idx;
int st[N];
int n,m;
void add(int a,int b)
{
e[idx]=b;
ne[idx]=h[a];
h[a]=idx++;
}
bool dfs(int x,int c)
{
st[x]=c;
for(int i=h[x];i!=-1;i=ne[i])
{
int t=e[i];
if(!st[t]) {
if(!dfs(t,3-c)) return false ;
}
else if(st[t]==c)return false ;
}
return true;
}
int main()
{
cin>>n>>m;
memset(h, -1, sizeof h);
while (m -- ){
int a,b;
cin>>a>>b;
add(a, b);
add(b,a);
}
bool flag =true;
for(int i=1;i<=n;i++)
{
if(!st[i])
{
if(!dfs(i,1))
{
flag=false;
break;
}
}
}
if(flag) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
return 0;
}
版权声明
本文为[Bright autumn leaves]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220344186811.html
边栏推荐
- 【C】 Guess the number, shut down the applet, and practice some branch loops
- Introduction to Alibaba's super large-scale Flink cluster operation and maintenance system
- Take a look at this guide when the Hackathon competition is going on
- Ivorysql 1.2 has come
- DataGrip闪退,如何解决?MySQL
- 10-personalized top-N sequential recommendation via revolutionary sequence embedding
- Oracle database management
- Deep learning and image recognition: principle and practice notes day_ seventeen
- Unittest unit test (I)
- How to generate PCB real-time snapshot in 3D in Ad
猜你喜欢

php. Ini configuration

Xiaomi and zhiting's smart cameras protect your family privacy

Implementation of small cases

These good works of finclip hacker marathon competition, come and have a look

English | Day11, 12 x sentence true research daily sentence (meaning group)
![[network experiment] / host / router / switch / gateway / Routing Protocol / rip + OSPF / DHCP](/img/dc/37ee91774be1f708d5c561b2e53444.png)
[network experiment] / host / router / switch / gateway / Routing Protocol / rip + OSPF / DHCP

Common convolutional neural network structures

Nacos 为什么这么强

Baidu offline map research and development -- laravel framework

GPU深度学习环境配置
随机推荐
What is the future direction of GPU?
English | Day11, 12 x sentence true research daily sentence (meaning group)
Rasa dialogue robot serial 1 lesson 121: the whole process demonstration of e-commerce retail dialogue robot operation process debugging of Rasa dialogue robot debugging project - 1
Uninstall Oracle
2021-11-06 database
【C】猜数字,关机小程序,一些分支循环的练手题
Daily practice (46): intersection of two arrays
容联七陌赋能企业智能化服务,重新定义客服价值
[server data recovery] a data recovery case in which multiple hard disks of server raid6 are offline successively
How to generate PCB real-time snapshot in 3D in Ad
解决方案| 快对讲调度系统:高效协作
Do447ansible tower navigation
Zhongshanghui ⺠ evolution of trading platform architecture: response to Apache shardingsphere
Quantitative evaluation rules for security evaluation of commercial password applications (2021 Edition)
Full summary of 18 tax categories of tax law with memory tips
SeNet || 注意力机制——源代码+注释
Mongodb - $match operation of aggregation pipeline
Deep learning and image recognition: principle and practice notes day_ 18 (target detection)
Why is Nacos so strong
[knowledge atlas] catalogue of financial securities knowledge atlas projects