Warning

This documents an unmaintained version of NetworkX. Please upgrade to a maintained version and see the current NetworkX documentation.

# strongly_connected_components¶

strongly_connected_components(G)[source]

Generate nodes in strongly connected components of graph.

Parameters: G (NetworkX Graph) – An directed graph. comp – A generator of sets of nodes, one for each strongly connected component of G. generator of sets NetworkXNotImplemented – If G is undirected.

Examples

Generate a sorted list of strongly connected components, largest first.

>>> G = nx.cycle_graph(4, create_using=nx.DiGraph())
>>> [len(c) for c in sorted(nx.strongly_connected_components(G),
...                         key=len, reverse=True)]
[4, 3]


If you only want the largest component, it’s more efficient to use max instead of sort.

>>> largest = max(nx.strongly_connected_components(G), key=len)


connected_components(), weakly_connected_components()