38 int64_t index, std::vector<int64_t> *visited) {
39 std::queue<int64_t> q;
42 (*visited)[index] = 1;
44 int64_t u = q.front();
46 for (uint64_t i = 0; i <
graph[u].size(); i++) {
58 }
else if ((*visited)[v] ==
77 std::vector<int64_t> visited(
82 for (uint64_t i = 0; i <
graph.size(); i++) {
101 std::vector<std::vector<int64_t>>
graph = {{1, 3}, {0, 2}, {1, 3}, {0, 2}};
107 std::vector<std::vector<int64_t>> graph_not_bipartite = {
108 {1, 2, 3}, {0, 2}, {0, 1, 3}, {0, 2}};
113 std::cout <<
"All tests have successfully passed!\n";
bool isBipartite(const std::vector< std::vector< int64_t > > &graph)
returns true if the given graph is bipartite else returns false
bool checkBipartite(const std::vector< std::vector< int64_t > > &graph, int64_t index, std::vector< int64_t > *visited)
function to check whether the passed graph is bipartite or not