当前位置:网站首页>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;
}边栏推荐
- Advanced level of C language (high level) pointer
- 【云原生】内存数据库如何发挥内存优势
- 外包干了三年,废了...
- Implementing data dictionary with JSP custom tag
- 聊聊异步编程的 7 种实现方式
- Bi she - college student part-time platform system based on SSM
- Interviewer: what development models do you know?
- Simple example of ros2 planning system plansys2
- How to * * labelimg
- 四、高性能 Go 语言发行版优化与落地实践 青训营笔记
猜你喜欢

English translation is too difficult? I wrote two translation scripts with crawler in a rage

The currently released SKU (sales specification) information contains words that are suspected to have nothing to do with baby

Advanced level of C language (high level) pointer

外包幹了三年,廢了...

Project practice five fitting straight lines to obtain the center line

Outlier detection technology of time series data

@component(““)

面试官:你都了解哪些开发模型?

海思芯片(hi3516dv300)uboot镜像生成过程详解

Cloud backup project
随机推荐
Write CPU yourself -- Chapter 9 -- learning notes
Torefs API and toref API
Blue Bridge Cup Birthday candles (violence)
Implementing data dictionary with JSP custom tag
Asynchronous components and suspend (in real development)
【性能压测】如何做好性能压测?
1141_ SiCp learning notes_ Functions abstracted as black boxes
After 95, Alibaba P7 published the payroll: it's really fragrant to make up this
在线直播系统源码,使用ValueAnimator实现view放大缩小动画效果
2、 Concurrent and test notes youth training camp notes
KBU1510-ASEMI电源专用15A整流桥KBU1510
1140_ SiCp learning notes_ Use Newton's method to solve the square root
聊聊异步编程的 7 种实现方式
Causes and solutions of oom (memory overflow)
"Xiaodeng in operation and maintenance" meets the compliance requirements of gdpr
ASEMI整流桥RS210参数,RS210规格,RS210封装
Simple example of ros2 planning system plansys2
考研失败,卷不进大厂,感觉没戏了
Why is the row of SQL_ The ranking returned by number is 1
Le Service MySQL manque dans le service informatique