Maths WorkshopMaths problems with full solutions
Exercise 1248Combinatorics › Graph theoryOlympiadAdded 4 Nov 2026

A graph is bipartite exactly when it has no odd cycle

#graph theory#bipartite graphs#colouring#cycles

Statement

A finite graph is bipartite if its vertices can be split into two classes such that every edge joins the two classes (equivalently, it can be coloured with 22 colours so that adjacent vertices get different colours). Prove that a graph is bipartite if and only if it contains no cycle of odd length.

Hint

For "if": in each connected component pick a root and colour each vertex by the parity of its distance to the root. If some edge joins two vertices of the same colour, build a closed walk of odd length, and show that an odd closed walk contains an odd cycle.

Show solutionHide solution

Solution

(⇒\Rightarrow) Suppose the classes are AA and BB. Going along a cycle, we alternate between AA and BB, and we return to the start, so the number of steps is even.

(⇐\Leftarrow) Assume there is no odd cycle. It suffices to colour each connected component separately. In a component choose a root rr and give a vertex xx the colour of the parity of d(x)d(x), the length of a shortest path from rr to xx.

Suppose an edge uvuv joins two vertices of the same parity. Then the walk "shortest path r→ur\to u, the edge uvuv, shortest path v→rv\to r" is a closed walk of length d(u)+1+d(v)d(u)+1+d(v), which is odd.

Claim. A closed walk of odd length contains an odd cycle.

*Proof by strong induction on the length LL.* If no vertex repeats (except the start/end), the walk is a cycle, of odd length LL. Otherwise some vertex ww occurs twice in the walk, which splits it into two closed walks (from ww to ww) whose lengths L1,L2L_1,L_2 are positive, smaller than LL, and add up to LL. One of them is odd; apply the induction hypothesis to it. □\square

So the edge uvuv would create an odd cycle, a contradiction. Hence every edge joins vertices of opposite parity, and the graph is bipartite.

Example. Trees, even cycles and grids have no odd cycle, so they can be 22-coloured. A triangle needs 33 colours.

Lesson. Colour by parity of distance; an odd closed walk always hides an odd cycle.