Depth-first search on a digraph, classifying every edge as tree, back, forward, or cross from the discover/finish times. Reads the Algs4 Digraph format (V, then E, then directed edges v w meaning v→w). A back edge proves a cycle; with none, reverse finish order is a topological sort.
Digraph): first line is the vertex count V,
second line is the edge count E, then E lines each holding a
directed edge v w read as v→w. Vertices are 0 … V−1.
Adjacency lists keep input order, and DFS runs from the chosen source first, then sweeps the
remaining vertices as new roots so the whole DFS forest is built.
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.