Graph Theory37 sections · 1633 units
Open in Course

Planets Queries II - Walkthrough

(Example execution)

Graph: f(1)=2,f(2)=3,f(3)=1,f(4)=2f(1) = 2, f(2) = 3, f(3) = 1, f(4) = 2. Cycle: 12311 \to 2 \to 3 \to 1. Tail: 44. Cycle length is 33, tail node 44 is distance 11 from cycle. Query (1,3)(1, 3): both in cycle. Indices: 11 at 00, 33 at 22. Distance: (20)mod3=2(2 - 0) \mod 3 = 2.

From node 11, go 22 steps to reach node 33. Query (4,3)(4, 3): 44 in tail (distance 11 to cycle at node 22, index 11). Jump to cycle, then (21)mod3=1(2 - 1) \mod 3 = 1. Total: 1+1=21 + 1 = 2.