A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://TheAlgorithms.github.io/C-Plus-Plus/d6/dd8/is__graph__bipartite_8cpp_source.html below:

TheAlgorithms/C++: graph/is_graph_bipartite.cpp Source File

Go to the documentation of this file. 55

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

(

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.

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