@not_implemented_for('undirected')
def kosaraju_strongly_connected_components(G, source=None):
 with nx.utils.reversed(G):
  post = list(nx.dfs_postorder_nodes(G, source=source))
 seen = set()
 while post:
  r = post.pop()
  if (r in seen):
   continue
  c = nx.dfs_preorder_nodes(G, r)
  new = {v for v in c if (v not in seen)}
  (yield new)
  seen.update(new)

@ not_implemented_for ( 'undirected' ) def kosaraju_strongly_connected_components ( G , source = None ) : with nx . utils . reversed ( G ) : post = list ( nx . dfs_postorder_nodes ( G , source = source ) ) seen = set ( ) while post : r = post . pop ( ) if ( r in seen ) : continue c = nx . dfs_preorder_nodes ( G , r ) new = { v for v in c if ( v not in seen ) } ( yield new ) seen . update ( new )
generate nodes in strongly connected components of graph .