Graph Theory37 sections · 1633 units
Open in Course

Problem - Planets Queries II

(CSES 1160)

You are given the same teleporter graph. Now answer queries: what is the minimum steps to get from planet xx to planet yy?

If impossible, output 1-1. You have up to 10510^5 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.