#NEWLINE# @ not_implemented_for ( 'undirected' ) #NEWLINE# def kosaraju_strongly_connected_components( G , source = None ) : #NEWLINE# #INDENT# "Generate nodes in strongly connected components of graph.\n\n    Parameters\n    ----------\n    G : NetworkX Graph\n        An directed graph.\n\n    Returns\n    -------\n    comp : generator of sets\n        A genrator of sets of nodes, one for each strongly connected\n        component of G.\n\n    Raises\n    ------\n    NetworkXNotImplemented:\n        If G is undirected.\n\n    Examples\n    --------\n    Generate a sorted list of strongly connected components, largest first.\n\n    >>> G = nx.cycle_graph(4, create_using=nx.DiGraph())\n    >>> nx.add_cycle(G, [10, 11, 12])\n    >>> [len(c) for c in sorted(nx.kosaraju_strongly_connected_components(G),\n    ...                         key=len, reverse=True)]\n    [4, 3]\n\n    If you only want the largest component, it's more efficient to\n    use max instead of sort.\n\n    >>> largest = max(nx.kosaraju_strongly_connected_components(G), key=len)\n\n    See Also\n    --------\n    strongly_connected_components\n\n    Notes\n    -----\n    Uses Kosaraju's algorithm.\n\n    " #NEWLINE# with nx . utils . reversed ( G ) : #NEWLINE# #INDENT# post = list ( nx . dfs_postorder_nodes ( G , source = source ) ) #NEWLINE# #UNINDENT# seen = set ( ) #NEWLINE# while post : #NEWLINE# #INDENT# r = post . pop ( ) #NEWLINE# if ( r in seen ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# c = nx . dfs_preorder_nodes ( seen , r ) #NEWLINE# new = { v for v in c if ( v not in seen ) } #NEWLINE# ( yield new ) #NEWLINE# seen . update ( new )