当前位置:网站首页>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
Yes
orNo
Indicates 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;
}
边栏推荐
- 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
- ROS2规划系统plansys2简单的例子
- 【leetcode】1020. Number of enclaves
- IO流 file
- The metauniverse of the platofarm farm continues to expand, with Dao governance as the core
- Project practice five fitting straight lines to obtain the center line
- URP - shaders and materials - simple lit
- 按键精灵采集学习-矿药采集及跑图
- 按键精灵脚本学习-关于天猫抢红包
- Implementing data dictionary with JSP custom tag
猜你喜欢
Example of Pushlet using handle of Pushlet
三、高质量编程与性能调优实战 青训营笔记
Initial experience of teambiion network disk (Alibaba cloud network disk)
Tencent's one-day life
海思芯片(hi3516dv300)uboot镜像生成过程详解
外包干了三年,废了...
How to * * labelimg
Abnova immunohistochemical service solution
抽丝剥茧C语言(高阶)数据的储存+练习
Asynchronous components and suspend (in real development)
随机推荐
Deep learning Flower Book + machine learning watermelon book electronic version I found
Leetcode-206. Reverse Linked List
How to * * labelimg
07_ Handout on the essence and practical skills of text measurement and geometric transformation
Composition API premise
Robot technology innovation and practice old version outline
四、高性能 Go 语言发行版优化与落地实践 青训营笔记
After 95, the CV engineer posted the payroll and made up this. It's really fragrant
按键精灵采集学习-矿药采集及跑图
MobaXterm
【云原生】内存数据库如何发挥内存优势
Fullgc problem analysis and solution summary
KBU1510-ASEMI电源专用15A整流桥KBU1510
leetcode:105. 从前序与中序遍历序列构造二叉树
2022-07-06:以下go语言代码是否会panic?A:会;B:不会。 package main import “C“ func main() { var ch chan struct
PostgreSQL source code (60) transaction system summary
关于二进制无法精确表示小数
PostgreSQL source code (59) analysis of transaction ID allocation and overflow judgment methods
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?
L'externalisation a duré trois ans.