Still Two Teams? — Solution & Editorial
Union-find with parity: store each node's color parity relative to its root. Joining two nodes in the same set with equal parity closes an odd cycle — bipartiteness dies. Path compression must recompute parities along the path.
Complexity: O(M α(N))
Watch out: The parity update on union — parity[ru] = p(u) ⊕ p(v) ⊕ 1 — and during compression are both easy to get backwards.