A graph with n nodes and undirected edges is bipartite if the nodes can be split into two groups so that every edge joins a node of one group to a node of the other (no edge inside a group). Return True if the graph is bipartite. The graph may have several components.
A triangle is not bipartite; a square is.
Example 1
Input:
is_bipartite(4, [[0, 1], [1, 2], [2, 3], [3, 0]])
Output:
True
Example 2
Input:
is_bipartite(3, [[0, 1], [1, 2], [2, 0]])
Output:
False
0 <= n <= 1000000 <= len(edges) <= 200000No results yet
Run your code to check it against the examples, or submit to run every test.