| 12 | } |
| 13 | |
| 14 | bool dfs(int node, int color, std::vector<std::vector<int>>& graph, std::vector<int>& colors) { |
| 15 | colors[node] = color; |
| 16 | for (int neighbor : graph[node]) { |
| 17 | // If the current neighbor has the same color as the current |
| 18 | // node, the graph is not bipartite. |
| 19 | if (colors[neighbor] == color) { |
| 20 | return false; |
| 21 | } |
| 22 | // If the current neighbor is not colored, color it with the |
| 23 | // other color and continue the DFS. |
| 24 | if (colors[neighbor] == 0 && !dfs(neighbor, -color, graph, colors)) { |
| 25 | return false; |
| 26 | } |
| 27 | } |
| 28 | return true; |
| 29 | } |
no outgoing calls
no test coverage detected