Approach hintTry it first, then revealHide
Try to two-colour every component with BFS or DFS, giving each neighbour the opposite colour; the graph fails only if an edge joins two vertices of the same colour. Remember that it may be disconnected.
Try to two-colour every component with BFS or DFS, giving each neighbour the opposite colour; the graph fails only if an edge joins two vertices of the same colour. Remember that it may be disconnected.