title: Find all nodes connected to n
body: <p>I need to find all the shortest paths between every pair of node in my directed graph. What I am doing is: </p>
  
  <pre><code>for i in A.nodes()
      for y in A.nodes()
          paths = nx.all_shortest_paths(G,i,y)
  </code></pre>
  
  <p>But this is very slow, I guess, because in the graph there are a lot of nodes that have no connection to i anyway. 
  Is there a way to optimize that process? I am already taking care that nodes with no possibility to be connected to others do not end up in A. </p>