Directed DFS & Edge Types

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.

650ms
Digraph G  ·  DFS forest
unseen
active (on stack)
done
tree
back
forward*
cross*
*digraphs only
Stack over time  ·  discover / finish intervals
Status
Press  Step  or  Play  to begin.
Active path  ·  the stack
empty
Bottom = root  ·  top = vertex being explored. A back edge points into this path.
Edge classification
Result
Run the traversal to classify the edges.
Edit / paste a digraph
Format (Sedgewick & Wayne 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.

Optional fixed layout: after the edges, add exactly 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.

Mixed-format tolerant: each edge occupies exactly one line. Pasting a weighted graph here (an extra third number per edge line) just ignores that weight, since this page is unweighted — no need to strip it out by hand.