Here's the problem statement:
The author's solution proposes a method using a spanning tree, but I discovered a different approach (in contest) involving bipartite graphs, specifically revolving around this trivial observation:
We can also prove that if a simple connected graph $$$G$$$ doesn't contain a cycle with odd length then it must be bipartite by running a simple $$$BFS$$$ from $$$1$$$ and assign colors according to depth.
Therefore, we can solve the problem by first running a standard $$$BFS$$$ from $$$1,$$$ then checking if the graph is bipartite. This can be done by iterating through edges $$$(u, v)$$$ and check the parity of $$$d_u + d_v,$$$ with $$$d_i$$$ being the depth of the vertex $$$i$$$ after the $$$BFS$$$ from $$$1.$$$
If for all edges $$$(u, v),$$$ $$$d_u + d_v$$$ is odd then we can conclude that there are no odd cycles (and print $$$-1$$$).
If there exists an edge $$$(U, V)$$$ that $$$d_U + d_V$$$ is even then $$$(U, V)$$$ is an edge in a odd cycle.
This is where another array comes in, $$$from$$$. We define $$$from_i$$$ as the vertex that "adds" the node $$$i$$$ into the $$$BFS$$$ queue, and $$$from_1=-1$$$ (details are in the source code).
We can find the odd cycle like so: start with a deque with $$$U$$$ at the back and $$$V$$$ at the end and continuously assign $$$U := from_U$$$ and $$$V := from_V$$$ until $$$U=V,$$$ then we can push $$$U$$$ to the back and finish finding the odd cycle.







