Draw your graph:
for(i = 0 to
graph.getVertCount())
if(!visited[i])
stack =
dsf(i)
setUnvisited(graph.vertices)
transpose(graph)
while(!stack.empty())
vert = stack.pop()
if(!visited[vert])
scc =
dfs(vert)
SHORT EXPLANATION
---------------------
1. Mark all vertices as unvisited.
2. Run a Depth-first search on every unvisited
vertex.
3. Whenever a DFS finishes add the vertex it was run on to
the stack.
4. Transpose the graph (-> reverse the direction of the
edges).
4. Pop from the stack and run a DFS on the vertex if it
hasn't been visited already.
- every finished DFS yields a list of vertices, which is a
strongly connected component
5. Repeat step 4 until the stack is empty.