File tree 3 files changed +36
-0
lines changed
3 files changed +36
-0
lines changed Original file line number Diff line number Diff line change 47
47
+ [ Floyd Warshall’s] ( algorithms/floyd_warshall.cpp )
48
48
+ [ Loop Detection] ( algorithms/topsort.cpp )
49
49
+ [ Topological Sort] ( algorithms/topsort.cpp )
50
+ + [ Bipartite Graph Check] ( algorithms/bipartite_graph_check.cpp )
50
51
+ [ Strongly Connected Component (Kosaraju)] ( algorithms/scc.cpp )
51
52
+ [ Lowest Common Ancestor(sparse table)] ( algorithms/lca.cpp )
52
53
+ [ Articulation Point] ( algorithms/articulation_point.cpp )
Original file line number Diff line number Diff line change
1
+ #include < vector>
2
+ #include < array>
3
+ #include < queue>
4
+
5
+ using namespace std ;
6
+
7
+ #define MAX 100000
8
+
9
+ vector<int > adj[MAX];
10
+ array<int , MAX> color;
11
+ array<bool , MAX> visited;
12
+
13
+ bool isGraphBipartite (int src) {
14
+ color.fill (-1 );
15
+ visited.fill (false );
16
+ queue<int > Q;
17
+ Q.push (src);
18
+ color[src] = 1 ;
19
+ visited[src] = true ;
20
+ while (!Q.empty ()) {
21
+ int u = Q.front ();
22
+ Q.pop ();
23
+ for (int i = 0 ; i < (int )adj[u].size (); i++) {
24
+ int v = adj[u][i];
25
+ if (!visited[v]) {
26
+ visited[v] = true ;
27
+ color[v] = 1 - color[u];
28
+ Q.push (v);
29
+ } else if (visited[v] and color[v] == color[u]) {
30
+ return false ;
31
+ }
32
+ }
33
+ }
34
+ return true ;
35
+ }
You can’t perform that action at this time.
0 commit comments