Alternatively, depending on the type of graph, namely directed , strongly or loosely coupled or non-oriented --create component subgraphs (sub_G), i.e.
(G.subgraph(c) for c in connected_components(G))
or if indicated:
nx.weakly_connected_component_subgraphs(G)
or nx.strongly_connected_component_subgraphs(G)
In addition, given that sub_G is a directed graph, check the strength of its connections, for example
nx.is_strongly_connected(sub_G)
or ng.is_weakly_connected(sub_G)
In combination or individually, these recommendations will reduce unnecessary verification of paths that do not exist due to the nature of the subgraph (s) of the component.
source share