Note

This is the documentation for the current state of the development branch of rustworkx. The documentation or APIs here can change prior to being released.

rustworkx.number_weakly_connected_components#

number_weakly_connected_components(graph, /)#

Find the number of 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.number_weakly_connected_components(G)
2

To get these components, see [weakly_connected_components].

If rx.number_weakly_connected_components(G) == 1, then rx.is_weakly_connected(G) is True.

For undirected graphs, see [number_connected_components].

Parameters:

graph (PyDiGraph) – The directed graph to find the number of weakly connected components in

Returns:

The number of weakly connected components in the graph

Return type:

int