55 std::vector<std::vector<int> >
84 adj[u - 1].push_back(v - 1);
85 adj[v - 1].push_back(u - 1);
109 for (
int current_edge = 0; current_edge <
n; ++current_edge) {
110 if (
side[current_edge] == -1) {
111 q.push(current_edge);
112 side[current_edge] = 0;
114 int current = q.front();
116 for (
auto neighbour :
adj[current]) {
117 if (
side[neighbour] == -1) {
118 side[neighbour] = (1 ^
side[current]);
121 check &= (
side[neighbour] !=
side[current]);
154 std::cout <<
"The given graph G1 is a bipartite graph\n";
156 std::cout <<
"The given graph G1 is not a bipartite graph\n";
159 std::cout <<
"The given graph G2 is a bipartite graph\n";
161 std::cout <<
"The given graph G2 is not a bipartite graph\n";
Class for representing graph as an adjacency list.
Graph(int size)
Constructor that initializes the graph on creation.
void addEdge(int u, int v)
Function that add an edge between two nodes or vertices of graph.
std::vector< int > side
stores the side of the vertex
std::vector< std::vector< int > > adj
adj stores the graph as an adjacency list
bool is_bipartite()
function to add edges to our graph
Functions for checking whether a graph is bipartite or not.