Advanced graphs and trees · 13 / 15 Exercise Hard

Is it bipartite?

Objective

A graph is bipartite if its nodes can be painted with two colours so that no edge joins two nodes of the same colour (equivalent to having no odd-length cycles). It is checked with a traversal that alternates the colours.

Instructions

  • The first line has n m (nodes and edges); then m lines a b (undirected edge). The graph may not be connected.
  • Show Bipartite or Not bipartite.
Input
4 4
0 1
1 2
2 3
3 0
Output
Bipartite

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise