For each planet, find the length of the cycle it eventually reaches. If the planet is in a cycle, output the cycle length. If it is in a tail, output the tail length plus cycle length. This tests your understanding of functional graph structure.
You need to identify cycles and compute distances for all nodes. The answer format is specific. I'll show you an efficient one-pass algorithm. You process each node exactly once using DFS with memoization. It is clean and fast.