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_strongly_connected_components#

number_strongly_connected_components(graph, /)#

Find the number of strongly connected components in a directed graph

A strongly connected component (SCC) is a maximal subset of vertices such that every vertex is reachable from every other vertex within that subset.

>>> G = rx.PyDiGraph()
>>> G.extend_from_edge_list([(0, 1), (1, 2), (3, 4)])
>>> rx.number_strongly_connected_components(G)
2

To get these components, see [strongly_connected_components].

If rx.number_strongly_connected_components(G) == 1, then rx.is_strongly_connected(G) is True.

For undirected graphs, see [number_connected_components].

Parameters:

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

Returns:

The number of strongly connected components in the graph

Return type:

int