This is really just two topological sorts:
.
The magic is in the fact that this works at all!
Terminology: forward reachable, backward reachable. If u and v are in the same strongly connected component, then v is both forward reachable and backward reachable from u (and vice versa).
Argue that G and
have the same strongly connected
components.
Never break up a strongly connected component during a traversal (forward or backward). Why?