Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a78d997

Browse files
Initial Commit
1 parent 580fc60 commit a78d997

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
***************************
3+
* *
4+
* Author: Swaraj Deep *
5+
* *
6+
***************************
7+
*/
8+
9+
// Bipartite graph test or two coloring test using dfs calls
10+
#include <iostream>
11+
#include <vector>
12+
13+
using namespace std;
14+
15+
bool is_bipartitie_graph(vector<vector<int>> &graph, int vertex, vector<bool> &visited, vector<int> &color, int col)
16+
{
17+
visited[vertex] = true;
18+
color[vertex] = col;
19+
for (int child: graph[vertex]) {
20+
if (!visited[child]) {
21+
if (is_bipartitie_graph (graph, child, visited, color, col ^ 1) == false) {
22+
return false;
23+
}
24+
} else {
25+
if (color[vertex] == color[child]) {
26+
return false;
27+
}
28+
}
29+
}
30+
return true;
31+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /