rustworkx.weakly_connected_components#
- weakly_connected_components(graph, /)#
Find the weakly connected components in a directed graph
A weakly connected component (WCC) is a maximal subset of vertices such that there is a path between any two vertices in the subset when the direction of edges is ignored. This means that if you treat the directed graph as an undirected graph, all vertices in a weakly connected component are reachable from one another.
>>> G = rx.PyDiGraph() >>> G.extend_from_edge_list([(0, 1), (1, 2), (3, 4)]) >>> rx.weakly_connected_components(G) [{0, 1, 2}, {3, 4}]
See also [strongly_connected_components].
To get just the number of these components, see [number_weakly_connected_components].
For undirected graphs, see [connected_components].
- Parameters:
graph (PyDiGraph) – The directed graph to find the weakly connected components in.
- Returns:
A list of sets of node indices of weakly connected components
- Return type:
list[set[int]]