solve(graph) — graph[i] lists the neighbours of node i in an undirected
graph (nodes are 0..n-1). The graph may be disconnected.
Return true if the nodes can be split into two groups such that every edge
joins a node of one group to a node of the other — equivalently, if the graph can be
2-colored, or has no odd cycle.
Examples
solve([[1,3],[0,2],[1,3],[0,2]]) → true // a 4-cycle
solve([[1,2,3],[0,2],[0,1,3],[0,2]]) → false // contains a triangle
solve([[1,2],[0,2],[0,1]]) → false
solve([[]]) → trueRemember to start a new search from every unvisited node: an odd cycle can hide
in a component the first search never reaches.
Sample tests