def directed_connected_components(digr):
 if (not digr.DIRECTED):
  raise Exception(('%s is not a directed graph' % digr))
 finishing_times = DFS_loop(digr.get_transpose())
 (nodes_explored, connected_components) = ([], [])
 for node in finishing_times[::(-1)]:
  component = []
  outer_dfs(digr, node, nodes_explored, component)
  if component:
   nodes_explored += component
   connected_components.append(component)
 return connected_components

def directed_connected_components ( digr ) : if ( not digr . DIRECTED ) : raise Exception ( ( '%s is not a directed graph' % digr ) ) finishing_times = DFS_loop ( digr . get_transpose ( ) ) ( nodes_explored , connected_components ) = ( [ ] , [ ] ) for node in finishing_times [ : : ( - 1 ) ] : component = [ ] outer_dfs ( digr , node , nodes_explored , component ) if component : nodes_explored += component connected_components . append ( component ) return connected_components
returns a list of strongly connected components in a directed graph using kosarajus two pass algorithm .