The question is, guys. I want to check the graph for bipartite by coloring the vertices of one lobe in red and the other in black. There are no edges between the tops of one beat.
Граф задаётся списком смежности: 5 2 3 2 3 4 0 1 0 1 1 The first line - the number of peaks, well, then, I think, is clear.
I run the crawl in depth. The code itself is here:
void dfs_visit(int v) { used[v] = true; color[v] = "red"; for (vector<int>::iterator it = graph[v].begin(); it != graph[v].end(); it++) { if (!used[*it]) { dfs_visit(*it); color[*it] = "black"; } } } The answer is incorrect:
1st graph share: 0
2nd share of the graph: 1 2 3 4
Correct answer:
1st graph share: 0 1
2nd share of the graph: 2 3 4
What is the problem? Tell me! Thank!