input: graph output: set of strongly connected components (sets of vertices)
S = empty stack;
while S does not contain all vertices do
Choose an arbitrary vertex v not in S;
DFS-Walk-push(v ) and each time that DFS finishes expanding a vertex u, push u onto S;
Reverse the directions of all arcs to obtain the transpose graph;
while S is nonempty do
v = pop(S);
if v is UNVISITED then
DFS-Walk(v );
The set of visited vertices will give the strongly connected component containing v;