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