Graph Theory37 sections · 1633 units
Open in Course

Planets Queries II - Analysis

Recognizing the functional graph pattern.

Pattern recognition:

  • Exactly one outgoing edge per node = functional graph
  • Structure: trees leading into cycles
  • Need distance queries

Approach: 1.1. Find cycles and identify which cycle each node eventually reaches

2.2. Compute distance from each node to its cycle

3.3. For query (a,b)(a, b):

  • If bb is an ancestor of aa (in the tree part), answer is depth difference
  • If both reach the same cycle, compute cycle distance
  • Otherwise, impossible

This requires careful decomposition of the functional graph.