This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
## Tarjan's algorithm for SCC detection
```
UNVISITED = -1
n = number of nodes in graph
g = adjacency list with directed edges
id = 0 # Used to give each node an id
sccCount = 0 # Used to count number of SCCs found
# Index i in these arrays represents node i
ids = [0, 0, ... 0, 0] # Length n
low = [0, 0, ... 0, 0] # Length n
onStack = [false, false, ..., false] # Length n
stack = an empty stack data structure
function findSccs():
for(i = 0; i < n; i++): ids[i] = UNVISITED
for(i = 0; i < n; i++):
if(ids[i] == UNVISITED):
dfs(i)
return low
function dfs(at):
stack.push(at)
onStack[at] = true
ids[at] = low[at] = id++
# Visit all neighbours & min low-link on callback
for(to : g[at]):
if(ids[to] == UNVISITED): dfs(to)
if(onStack[to]): low[at] = min(low[at],low[to])
# After having visited all the neighbours of ‘at’ # if we're at the start of a SCC empty the seen