code: def construct_initial_pivots(graph, node_arc_data, spanning_tree):
      cost = node_arc_data.cost
      pi = node_arc_data.pi
      source = node_arc_data.source
      target = node_arc_data.target
      supply = node_arc_data.supply
  
      n1 = graph.n
      n2 = graph.m
      n_nodes = graph.n_nodes
      n_arcs = graph.n_arcs
  
      state = spanning_tree.state
  
      total = 0
      supply_nodes = []
      demand_nodes = []
  
      for u in range(n_nodes):
          curr = supply[n_nodes - u - 1]  # _node_id(u)
          if curr > 0:
              total += curr
              supply_nodes.append(u)
          elif curr < 0:
              demand_nodes.append(u)
  
      arc_vector = []
      if len(supply_nodes) == 1 and len(demand_nodes) == 1:
          # Perform a reverse graph search from the sink to the source
          reached = np.zeros(n_nodes, dtype=np.bool_)
          s = supply_nodes[0]
          t = demand_nodes[0]
          stack = []
          reached[t] = True
          stack.append(t)
          while len(stack) > 0:
              u = stack[-1]
              v = stack[-1]
              stack.pop(-1)
              if v == s:
                  break
  
              first_arc = n_arcs + v - n_nodes if v >= n1 else -1
              for a in range(first_arc, -1, -n2):
                  u = a // n2
                  if reached[u]:
                      continue
  
                  j = arc_id(a, graph)
                  if INFINITY >= total:
                      arc_vector.append(j)
                      reached[u] = True
                      stack.append(u)
  
      else:
          # Find the min. cost incomming arc for each demand node
          for i in range(len(demand_nodes)):
              v = demand_nodes[i]
              c = MAX
              min_cost = MAX
              min_arc = INVALID
              first_arc = n_arcs + v - n_nodes if v >= n1 else -1
              for a in range(first_arc, -1, -n2):
                  c = cost[arc_id(a, graph)]
                  if c < min_cost:
                      min_cost = c
                      min_arc = a
  
              if min_arc != INVALID:
                  arc_vector.append(arc_id(min_arc, graph))
  
      # Perform heuristic initial pivots
      in_arc = -1
      for i in range(len(arc_vector)):
          in_arc = arc_vector[i]
          # Bad arcs
          if (
              state[in_arc]
              * (cost[in_arc] + pi[source[in_arc]] - pi[target[in_arc]])
              >= 0
          ):
              continue
  
          join = find_join_node(
              source,
              target,
              spanning_tree.succ_num,
              spanning_tree.parent,
              in_arc,
          )
          leaving_arc_data = find_leaving_arc(
              join, in_arc, node_arc_data, spanning_tree
          )
          if leaving_arc_data.delta >= MAX:
              return False, in_arc
  
          update_flow(
              join,
              leaving_arc_data,
              node_arc_data,
              spanning_tree,
              in_arc,
          )
          if leaving_arc_data.change:
              update_spanning_tree(
                  spanning_tree, leaving_arc_data, join, in_arc, source
              )
              update_potential(
                  leaving_arc_data, pi, cost, spanning_tree
              )
  
      return True, in_arc
  
imports: import numpy
  import numba
  from collections import namedtuple
  from enum import Enum, IntEnum
label_desc: Use image node_id 9 for calling a global function with example usage: construct_initial_pivots(graph, node_arc_data, spanning_tree) and returns: True,  in_arc, False,  in_arc