Strong components · Kosaraju

Group towns that allow round trips. From any town in a group, you can reach every other town in that group and come back, even on one-way streets.

Record finish order, then reverse every arrow. Start the second traversal from the last-finished towns and paint one group at a time.

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