Two depth-first passes find the strongly connected components of a digraph. Phase 1 runs DFS on the reverse graph Gᴿ and records the finish order. Phase 2 runs DFS on G, taking sources in reverse postorder of that first pass — and every DFS tree it grows is exactly one strong component. Format: Algs4 Digraph (V, then E, then directed edges v w).
Digraph): vertex count V, then edge count
E, then E directed edges v w read as v→w. The reverse graph
Gᴿ is built automatically for Phase 1. Phase 1 and Phase 2 each sweep vertices 0 … V−1
as roots; Phase 2 visits them in the reverse postorder produced by Phase 1.
V more lines of
x y — one pair per vertex, in order — to pin down your own layout instead of the
automatic one. Any numeric scale works; it's auto-centred and scaled to fit, preserving relative
position and aspect ratio. Loading a graph always fills the box back in with its current layout's
coordinates so you can nudge them; tick the box above to see the plain format instead.