#include<bits/stdc++.h>
using namespace std;
bool dfs(int node, int col, int color[], vector<vector<int>> &adj) {
color[node] = col;
// traverse adjacent nodes
for(auto it : adj[node]) {
// if uncoloured
if(color[it] == -1) {
if(dfs(it, !col, color, adj) == false) return false;
}
// if previously coloured and have the same colour
else if(color[it] == col) {
return false;
}
}
return true;
}
bool isGraphBirpatite(vector<vector<int>> &edges) {
// Write your code here.
int n = edges.size();
int m = edges[0].size();
//Queue for BFS
queue <int> q;
//Array to mark the color of the nodes
vector<int> vis(n,-1);
//Creating adjacency list from the matrix
vector<vector<int>> adj(n);
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(edges[i][j]==1){
adj[i].push_back(j);
adj[j].push_back(i);
}
}
}
int color[n];
for(int i = 0;i<n;i++) color[i] = -1;
// for connected components
for(int i = 0;i<n;i++) {
if(color[i] == -1) {
if(dfs(i, 0, color, adj) == false)
return false;
}
}
return true;
}