You are given planets where each planet has a teleporter to another planet. Answer queries: starting from planet , where are you after steps? can be up to . This is the direct application of binary lifting. Each planet is a node, and the teleporter defines .
Simulating steps times out. I'll show you how to build the jump table and answer queries efficiently. The preprocessing takes , but each query is .
Space complexity is for the data structures used.