code: def edmonds_karp_impl(G, s, t, capacity, residual, cutoff):
      """Implementation of the Edmonds-Karp algorithm."""
      if s not in G:
          raise nx.NetworkXError(f"node {str(s)} not in graph")
      if t not in G:
          raise nx.NetworkXError(f"node {str(t)} not in graph")
      if s == t:
          raise nx.NetworkXError("source and sink are the same node")
  
      if residual is None:
          R = build_residual_network(G, capacity)
      else:
          R = residual
  
      # Initialize/reset the residual network.
      for u in R:
          for e in R[u].values():
              e["flow"] = 0
  
      if cutoff is None:
          cutoff = float("inf")
      R.graph["flow_value"] = edmonds_karp_core(R, s, t, cutoff)
  
      return R
  
imports: import networkx
  from networkx.algorithms.flow.utils import build_residual_network
label_desc: Use image node_id 2 for calling a global function with example usage: edmonds_karp_impl(G, s, t, capacity, residual, cutoff) and returns: R