Core idea
Tarjan's algorithm finds SCCs in a single DFS pass.
It maintains an id, a low-link value, and a boolean for whether a node is on the current stack.
An SCC is found when a node's id matches its low-link value after returning from its descendants.
How it works
- Run DFS, assigning IDs and low-link values, pushing nodes to a stack.
- Update a node's low-link value based on descendants and back-edges to nodes on the stack.
- If a node's ID equals its low-link value, it is the root of an SCC.
- Pop the stack to extract all nodes in this newly discovered SCC.