public IDictionary <GraphNode <T>, T> DfsConnectedComponents(UndirectedGraph <T> graph) { _nodeToScc.Clear(); graph.ClearNodeColors(); foreach (var node in graph.Nodes) { if (node.Color == Color.Colored) { continue; } ComponentVisit(node, node.Label, graph.Neighbors); } return(_nodeToScc); }
public static bool IsBipartite(UndirectedGraph <T> graph) { foreach (var node in graph.Nodes) { //if a node is colored, it has been assigned to a component and checked if (node.Color != Color.Uncolored) { continue; } if (!IsComponentBipartite(graph, node)) { return(false); } } graph.ClearNodeColors(); return(true); }