Suppose first that is bipartite. As one traverses any cycle in a graph, its vertices alternate between the two vertex classes. Returning to the initial class therefore requires an even number of edges, so contains no odd cycle.
Conversely, suppose that has no odd cycle. Work separately in each connected component of a graph, choose a root , and put
where is the graph distance. If adjacent vertices were in the same class, then and parity would force . Choose a breadth-first spanning tree. The two tree paths from to and diverge at some last common vertex; their remaining segments have equal length, and adjoining the edge gives an odd cycle. This contradiction shows that every edge joins to , proving the odd-cycle characterization of bipartite graphs.