forked from ravikartar/hacktoberfest2022
-
Notifications
You must be signed in to change notification settings - Fork 3
/
bipergraph.cpp
49 lines (46 loc) · 853 Bytes
/
bipergraph.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include<bits/stdc++.h>
using namespace std;
int color[100];
bool dfs(int node,vector<int> adj[],vector<int> &vis,int col){
vis[node]=1;
color[node]=col;
for(auto it:adj[node]){
if(!vis[it])
{
if(dfs(it,adj,vis,col^1)==false)
return false;
}
else
{
if(color[node]==color[it])
return false;
}
}
return true;
}
int main(){
int n,m;
cin>>n>>m;
vector<int> adj[n+1];
vector<int> vis(n+1,0);
for(int i=0;i<m;i++)
{
int u,v;
cin>>u>>v;
adj[u].push_back(v);
adj[v].push_back(u);
}
bool flag=true;
for(int i=1;i<=n;i++)
{
if(!vis[i])
{
if(dfs(i,adj,vis,0)==false)
flag=false;
}
}
if(flag)
cout<<"Bipartile graph";
else
cout<<"Not bipartile graph";
}