std::vector<std::vector<int> >
68 side.resize(
n, -1);
84 adj[u - 1].push_back(v - 1);
85 adj[v - 1].push_back(u - 1);
109 for(
intcurrent_edge = 0; current_edge <
n; ++current_edge) {
110 if(
side[current_edge] == -1) {
111q.push(current_edge);
112 side[current_edge] = 0;
114 intcurrent = q.front();
116 for(
autoneighbour :
adj[current]) {
117 if(
side[neighbour] == -1) {
118 side[neighbour] = (1 ^
side[current]);
121check &= (
side[neighbour] !=
side[current]);
154std::cout <<
"The given graph G1 is a bipartite graph\n";
156std::cout <<
"The given graph G1 is not a bipartite graph\n";
159std::cout <<
"The given graph G2 is a bipartite graph\n";
161std::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.
bool is_bipartite()
function to add edges to our 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
void addEdge(int u, int v)
Function that add an edge between two nodes or vertices of graph.
Functions for checking whether a graph is bipartite or not.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4