For marking strong components.

Pseudo-code

PushPostRevDFS(𝑣, 𝑆):1Mark(𝑣)2for all edges 𝑢𝑣𝐸:3if 𝑢 is unmarked:4PushPostRevDFS(𝑢,𝑆)56𝑆.Push(𝑣)LabelOneDFS(𝑣, 𝑟):1𝑣.𝑟𝑜𝑜𝑡𝑟2for all edges 𝑣𝑤𝐸:3if 𝑤.𝑟𝑜𝑜𝑡=none:4LabelOneDFS(𝑤,𝑟)5KosarajuSharir(𝐺):1𝑆 stack()2for all vertices 𝑣𝑉:3Unmark(𝑣)4𝑣.𝑟𝑜𝑜𝑡none56for all vertices 𝑣𝑉:// Phase 17if 𝑣 is unmarked:8PushPostRevDFS(𝑣,𝑆)910while 𝑆 is not empty:// Phase 211𝑣𝑆.Pop( )12if 𝑣.𝑟𝑜𝑜𝑡=none:13LabelOneDFS(𝑣,𝑣)14

Runtime

𝑂(|𝑉|+|𝐸|)