当前位置:网站首页>242. Bipartite graph determination
242. Bipartite graph determination
2022-07-07 07:35:00 【Recursions】
Given a with n A graph of vertices .
To dye every vertex on a graph , And make the adjacent vertices have different colors .
Ask if you can dye with up to two colors ? The title guarantees no double edges and self rings .
Input
- The first line is an integer n(1≤n≤1000), Represents the number of vertices
- Next, there are two integers in each line x and y, It means a vertex x and y There is a side between ,0≤x,y<n,x≠y
- With
EOF(end of file)As the end of edge data
Output
YesorNoIndicates whether two colors can be used for dyeing
Examples 1
Input
3 0 1 1 2 2 0
Output
No
#include<bits/stdc++.h>
using namespace std;
int n;
int color[1001];
vector<int>e[1001];
bool dfs(int v,int c)
{
color[v]=c;
for(int i=0;i<e[i].size();i++)
{
if(color[e[v][i]]==c)
return false;
if(color[e[v][i]]==0&&!dfs(e[v][i],-c))
return false;
}
return true;
}
int main()
{
while(cin>>n)
{
for(int i=0;i<n;i++)
{
int v1,v2;
cin>>v1>>v2;
e[v1].push_back(v2);
e[v2].push_back(v1);
}
for(int i=0;i<n;i++){
if(color[i]==0){
if(!dfs(i,1)){
cout<<"No"<<endl;
return 0;
}
}
}
cout<<"Yes"<<endl;
}
return 0;
}边栏推荐
- Tumor immunotherapy research prosci Lag3 antibody solution
- Sqlmap tutorial (IV) practical skills three: bypass the firewall
- I failed in the postgraduate entrance examination and couldn't get into the big factory. I feel like it's over
- L'externalisation a duré trois ans.
- Summary of customer value model (RFM) technology for data analysis
- Deep learning Flower Book + machine learning watermelon book electronic version I found
- JS small exercise ---- time sharing reminder and greeting, form password display hidden effect, text box focus event, closing advertisement
- 记一个并发规则验证实现
- 机器人技术创新与实践旧版本大纲
- 外包干了三年,废了...
猜你喜欢

Initial experience of teambiion network disk (Alibaba cloud network disk)

How to * * labelimg

Sqlmap tutorial (IV) practical skills three: bypass the firewall

mips uclibc 交叉编译ffmpeg,支持 G711A 编解码

07_ Handout on the essence and practical skills of text measurement and geometric transformation

idea添加类注释模板和方法模板

Project practice five fitting straight lines to obtain the center line

Stockage et pratique des données en langage C (haut niveau)

外包干了三年,废了...

1、 Go knowledge check and remedy + practical course notes youth training camp notes
随机推荐
C language (high-level) data storage + Practice
The annual salary of general test is 15W, and the annual salary of test and development is 30w+. What is the difference between the two?
After 95, the CV engineer posted the payroll and made up this. It's really fragrant
[Linux] process control and parent-child processes
Introduction to abnova's in vitro mRNA transcription workflow and capping method
Cloud backup project
BGP experiment (1)
After 95, Alibaba P7 published the payroll: it's really fragrant to make up this
Blue Bridge Cup Netizen age (violence)
Stockage et pratique des données en langage C (haut niveau)
Wechat applet full stack development practice Chapter 3 Introduction and use of APIs commonly used in wechat applet development -- 3.10 tabbar component (I) how to open and use the default tabbar comp
【云原生】内存数据库如何发挥内存优势
Wechat applet full stack development practice Chapter 3 Introduction and use of APIs commonly used in wechat applet development -- 3.9 introduction to network interface (IX) extending the request3 met
English translation is too difficult? I wrote two translation scripts with crawler in a rage
2、 Concurrent and test notes youth training camp notes
4、 High performance go language release optimization and landing practice youth training camp notes
計算機服務中缺失MySQL服務
Simple example of ros2 planning system plansys2
Fullgc problem analysis and solution summary
How to * * labelimg