number_weakly_connected_components#

number_weakly_connected_components(G)[source]#

Returns the number of weakly connected components in G.

Parameters:
GNetworkX graph

A directed graph.

Returns:
ninteger

Number of weakly connected components

Raises:
NetworkXNotImplemented

If G is undirected.

Notes

For directed graphs only.

Examples

>>> G = nx.DiGraph([(0, 1), (2, 1), (3, 4)])
>>> nx.number_weakly_connected_components(G)
2
----

Additional backends implement this function

cugraph : GPU-accelerated backend.