Let L be a list of pairs – e.g., L = { {1,2}, {3,4}, {2,1}, {4,5}, {9,10}, {5,8} } – where pair {t,h} denotes the directed arc from node t to h. Let G be the digraph determined by these arcs.
I want the “disconnected components” of G but want the nodes in G-order. Neither ConnectedComponents(G) nor WeaklyConnectedComponents(G) yield this. So, for L above the answer is { {1,2,1}, {3,4,5,8}, {9,10} } (I’d change {1,2,1} to be {1,2}).
Although VertexInDegree and VertexOutDegree (applied to the output of WeaklyConnectedComponents) easily dispatch this task, I’m hoping there’s a slicker easier way that avoids the need to view L as a graph – if you see one, I’m all ears. I’ve unsuccessfuly tried GatherBy and MatchQ.
Thanks!