code: def edmonds_karp_core(R, s, t, cutoff):
      """Implementation of the Edmonds-Karp algorithm."""
      R_nodes = R.nodes
      R_pred = R.pred
      R_succ = R.succ
  
      inf = R.graph["inf"]
  
      def augment(path):
          """Augment flow along a path from s to t."""
          # Determine the path residual capacity.
          flow = inf
          it = iter(path)
          u = next(it)
          for v in it:
              attr = R_succ[u][v]
              flow = min(flow, attr["capacity"] - attr["flow"])
              u = v
          if flow * 2 > inf:
              raise nx.NetworkXUnbounded(
                  "Infinite capacity path, flow unbounded above."
              )
          # Augment flow along the path.
          it = iter(path)
          u = next(it)
          for v in it:
              R_succ[u][v]["flow"] += flow
              R_succ[v][u]["flow"] -= flow
              u = v
          return flow
  
      def bidirectional_bfs():
          """Bidirectional breadth-first search for an augmenting path."""
          pred = {s: None}
          q_s = [s]
          succ = {t: None}
          q_t = [t]
          while True:
              q = []
              if len(q_s) <= len(q_t):
                  for u in q_s:
                      for v, attr in R_succ[u].items():
                          if (
                              v not in pred
                              and attr["flow"] < attr["capacity"]
                          ):
                              pred[v] = u
                              if v in succ:
                                  return v, pred, succ
                              q.append(v)
                  if not q:
                      return None, None, None
                  q_s = q
              else:
                  for u in q_t:
                      for v, attr in R_pred[u].items():
                          if (
                              v not in succ
                              and attr["flow"] < attr["capacity"]
                          ):
                              succ[v] = u
                              if v in pred:
                                  return v, pred, succ
                              q.append(v)
                  if not q:
                      return None, None, None
                  q_t = q
  
      # Look for shortest augmenting paths using breadth-first search.
      flow_value = 0
      while flow_value < cutoff:
          v, pred, succ = bidirectional_bfs()
          if pred is None:
              break
          path = [v]
          # Trace a path from s to v.
          u = v
          while u != s:
              u = pred[u]
              path.append(u)
          path.reverse()
          # Trace a path from v to t.
          u = v
          while u != t:
              u = succ[u]
              path.append(u)
          flow_value += augment(path)
  
      return flow_value
  
imports: import networkx
  from networkx.algorithms.flow.utils import build_residual_network
label_desc: Use image node_id 1 for calling a global function with example usage: edmonds_karp_core(R, s, t, cutoff) and returns: flow_value, flow, None,  None,  None, None,  None,  None, v,  pred,  succ, v,  pred,  succ