code: def floyd_warshall_predecessor_and_distance(G, weight="weight"):
      """Find all-pairs shortest path lengths using Floyd's algorithm.
  
      Parameters
      ----------
      G : NetworkX graph
  
      weight: string, optional (default= 'weight')
         Edge data key corresponding to the edge weight.
  
      Returns
      -------
      predecessor,distance : dictionaries
         Dictionaries, keyed by source and target, of predecessors and distances
         in the shortest path.
  
      Examples
      --------
      >>> G = nx.DiGraph()
      >>> G.add_weighted_edges_from(
      ...     [
      ...         ("s", "u", 10),
      ...         ("s", "x", 5),
      ...         ("u", "v", 1),
      ...         ("u", "x", 2),
      ...         ("v", "y", 1),
      ...         ("x", "u", 3),
      ...         ("x", "v", 5),
      ...         ("x", "y", 2),
      ...         ("y", "s", 7),
      ...         ("y", "v", 6),
      ...     ]
      ... )
      >>> predecessors, _ = nx.floyd_warshall_predecessor_and_distance(G)
      >>> print(nx.reconstruct_path("s", "v", predecessors))
      ['s', 'x', 'u', 'v']
  
      Notes
      -----
      Floyd's algorithm is appropriate for finding shortest paths
      in dense graphs or graphs with negative weights when Dijkstra's algorithm
      fails.  This algorithm can still fail if there are negative cycles.
      It has running time $O(n^3)$ with running space of $O(n^2)$.
  
      See Also
      --------
      floyd_warshall
      floyd_warshall_numpy
      all_pairs_shortest_path
      all_pairs_shortest_path_length
      """
      from collections import defaultdict
  
      # dictionary-of-dictionaries representation for dist and pred
      # use some defaultdict magick here
      # for dist the default is the floating point inf value
      dist = defaultdict(lambda: defaultdict(lambda: float("inf")))
      for u in G:
          dist[u][u] = 0
      pred = defaultdict(dict)
      # initialize path distance dictionary to be the adjacency matrix
      # also set the distance to self to 0 (zero diagonal)
      undirected = not G.is_directed()
      for u, v, d in G.edges(data=True):
          e_weight = d.get(weight, 1.0)
          dist[u][v] = min(e_weight, dist[u][v])
          pred[u][v] = u
          if undirected:
              dist[v][u] = min(e_weight, dist[v][u])
              pred[v][u] = v
      for w in G:
          dist_w = dist[w]  # save recomputation
          for u in G:
              dist_u = dist[u]  # save recomputation
              for v in G:
                  d = dist_u[w] + dist_w[v]
                  if dist_u[v] > d:
                      dist_u[v] = d
                      pred[u][v] = pred[w][v]
      return dict(pred), dict(dist)
  
imports: import networkx
label_desc: Use image node_id 2 for calling a global function with example usage: floyd_warshall_predecessor_and_distance(G, weight) and returns: dict,  dict