Pattern
Functional / Successor Graphs
Every node has exactly one outgoing edge, so each component is a cycle with trees hanging off it; reason about tails, cycles, and k-step successors.
Learn firstGraph BFS / DFSFast & Slow Pointers
0%
mastery
0/9 solved
0/9 solved
Recognise it
The signal
next[i] arrays, permutations, teleporters
1Brute force
Simulate k steps per query.
2The observation
Step-by-step simulation: cycles repeat, and binary lifting jumps 2j steps.
3Why it works
Following successors from any node eventually enters exactly one cycle.
Reach for it when
- +where am I after k steps
- +length of cycle reached from each node
Not when
- ×out-degree > 1 (general graph)
Practice
0/9 solved
- BadgeCodeforces1000
- Permutation GameCodeforces1300
- Cyclic ArrayCSESMedium
- Planets Queries ICSESMedium
- Throw the Ball (k up to 1e12)OracleOAMedium
- Find the Duplicate NumberMedium
- Planets Queries IICSESHard
- Planets CyclesCSESHard
- Longest Cycle in a GraphHard
Pitfalls
Misconceptions
- !treating it as a tree (there is always a cycle per component)
Go deeper1 combinations · resources
Combinations
Functional / Successor Graphs+Binary Lifting & LCA
teleporters/successor after k steps; first time reaching b from a
- Functional / Successor Graphs:
- every node has one successor
- Binary Lifting & LCA:
- k-step successor in O(log k)