You are given the same teleporter graph. Now answer queries: what is the minimum steps to get from planet to planet ?
If impossible, output . You have up to queries. This combines cycle detection, binary lifting, and case analysis. You need to precompute cycle structure and handle all reachability cases. It is more complex than Planets Queries I. I'll walk through the complete solution with all edge cases. You will see how to handle tail-to-tail, tail-to-cycle, and cycle-to-cycle queries.