// implements Kosaraju's algorithm (https://en.wikipedia.org/wiki/Kosaraju%27s_algorithm) public IDictionary <GraphNode <T>, T> KosarajuScc(DirectedGraph <T> graph) { _nodeToScc.Clear(); _visitOrder = new LinkedList <GraphNode <T> >(); foreach (var node in graph.Nodes) { Visit(graph, node); } graph.ClearNodeColors(); var inNeighbors = graph.GetInNeighbors(); foreach (var node in _visitOrder) { if (node.Color == Color.Colored) { continue; } ComponentVisit(node, node.Label, inNeighbors); } return(_nodeToScc); }