当前位置:网站首页>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;
}边栏推荐
- 机器人技术创新与实践旧版本大纲
- 4、 High performance go language release optimization and landing practice youth training camp notes
- Abnova immunohistochemical service solution
- Outsourcing for four years, abandoned
- Causes and solutions of oom (memory overflow)
- Detailed explanation of neo4j installation process
- What is the difference between TCP and UDP?
- 按键精灵采集学习-矿药采集及跑图
- Torefs API and toref API
- JS small exercise
猜你喜欢

A concurrent rule verification implementation

Bindingexception exception (error reporting) processing

四、高性能 Go 语言发行版优化与落地实践 青训营笔记

Communication between non parent and child components

Fast quantitative, abbkine protein quantitative kit BCA method is coming!

Jenkins远程构建项目超时的问题

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

聊聊异步编程的 7 种实现方式

Apache AB stress test

At the age of 20, I got the ByteDance offer on four sides, and I still can't believe it
随机推荐
修改Jupyter Notebook文件路径
外包干了四年,废了...
Unity C function notes
1、 Go knowledge check and remedy + practical course notes youth training camp notes
Tumor immunotherapy research prosci Lag3 antibody solution
leetcode:105. 从前序与中序遍历序列构造二叉树
Introduction to abnova's in vitro mRNA transcription workflow and capping method
Project practice five fitting straight lines to obtain the center line
[cloud native] how to give full play to memory advantage of memory database
Implementing data dictionary with JSP custom tag
07_ Handout on the essence and practical skills of text measurement and geometric transformation
URP - shaders and materials - light shader lit
抽絲剝繭C語言(高階)數據的儲存+練習
Differences between H5 architecture and native architecture
Flexible layout (I)
Kuboard无法发送邮件和钉钉告警问题解决
Readonly read only
Causes and solutions of oom (memory overflow)
Detailed explanation of neo4j installation process
"Xiaodeng in operation and maintenance" meets the compliance requirements of gdpr