Core idea: You need an Euler path from level to level .
Conditions for directed Euler path:
- Vertex (start):
- Vertex (end):
- All other vertices:
If these conditions aren't met exactly, output "IMPOSSIBLE".
Also check: The graph must be connected (underlying undirected graph).