def __init__(self, graph: GraphMatrix, list_vertices: List[int] = None): num_vertices: int = graph.number_of_vertices() self.marked: List[bool] = [False] * num_vertices self.id: List = [None] * num_vertices self.count: int = 0 if not list_vertices: list_vertices = graph.get_vertices() for vertice in list_vertices: if not self.marked[vertice]: self.__dfs(graph, vertice) self.count += 1
def __init__(self, graph: GraphMatrix, list_of_vertices: List[int] = None): if not graph.digraph: raise ValueError("this graph is not directed") self.color: List[Color] = [Color.WHITE] * graph.number_of_vertices() self.discovered_vertice_time: List = [None ] * graph.number_of_vertices() self.final_vertice_time: List = [None] * graph.number_of_vertices() self.predecessor: List = [None] * graph.number_of_vertices() self.count: int = 0 if not list_of_vertices: list_of_vertices = graph.get_vertices() for vertice in list_of_vertices: if self.color[vertice] != Color.BLACK: self.run(graph, vertice)