The problem can be reduced to two sub problems:
- Generate all combinations of pairs. This can be solved using backtrack.
- For each combination test if there is a cycle. This can be solved by exhaustive search: starting from each wormhole, and try move the number of total wormholes, and repeat, until all wormholes are tested.
|