Strong components · Tarjan

Find groups of towns on a one-way map where you can travel between any two towns and get back. Tarjan finds the groups in a single exploration.

Open vertices wait on a stack. The low-link value tracks the earliest reachable mark still relevant to this search. At a component root, pop the whole group.

With adjacency lists, traversal takes O(V + E) time for V vertices and E edges.