Two-Colouring a Graph (Bipartite Check)

medium
Unit 8 · Graphs I0/2 to milestone

Can you split people into two teams so that no two people who dislike each other are on the same team? That's asking whether a graph is bipartite, i.e. two-colourable.

Implement two_color(n, edges) for nodes 0..n-1 and undirected edges. Return a list of colours (0 or 1) for each node if possible, or None if not. Use BFS from each uncoloured node in index order, giving the starting node colour 0. The graph may be disconnected.

#graphs#bfs2 visible + 2 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Two-Colouring a Graph (Bipartite Check) · TechGradify