# How to compute the sorted connected components of a graph efficiently?

The code below computes the connected components of the undirected graph and sorts them according to the directed graph. It is possible since by (the real) definition of edges, the subgraph generated by any connected component will always be a path graph. Or said differently, the undirected graph is a disjoint union of path graphs.

edges = Uncompress[FromCharacterCode[
Flatten[ImageData[Import["http://i.stack.imgur.com/ujaNL.png"],"Byte"]]]]

sortedComps = With[{dirGraph = DirectedEdge @@@ edges,
comps = ConnectedComponents[UndirectedEdge @@@ edges]},
FindHamiltonianPath[Subgraph[dirGraph, #]] & /@ comps];


The evaluation is horribly slow. How to compute sortedComps more efficiently?

TopologicalSort /@ WeaklyConnectedGraphComponents[DirectedEdge @@@ edges]