Comments

Another way to prove this is by noting that the graph is bipartite.

This can be solved using deque