Graph Theory37 sections · 1633 units
Open in Course

Problem - Planets Queries II

CSES 1160 - Functional graphs.

Problem: There are nn planets. Each planet has a teleporter to exactly one other planet. Given queries (a,b)(a, b), find the minimum teleportations to get from aa to bb, or report it's impossible.

Link: CSES 1160

Constraints:

  • 1n,q2×1051 \leq n, q \leq 2 \times 10^5

Note: Each planet has exactly one outgoing teleporter. This is a functional graph.