code: def update_spanning_tree(
      spanning_tree, leaving_arc_data, join, in_arc, source
  ):
      parent = spanning_tree.parent
      thread = spanning_tree.thread
      rev_thread = spanning_tree.rev_thread
      succ_num = spanning_tree.succ_num
      last_succ = spanning_tree.last_succ
      forward = spanning_tree.forward
      pred = spanning_tree.pred
  
      u_out = leaving_arc_data.u_out
      u_in = leaving_arc_data.u_in
      v_in = leaving_arc_data.v_in
  
      old_rev_thread = rev_thread[u_out]
      old_succ_num = succ_num[u_out]
      old_last_succ = last_succ[u_out]
      v_out = parent[u_out]
  
      u = last_succ[u_in]  # the last successor of u_in
      right = thread[u]  # the node after it
  
      # Handle the case when old_rev_thread equals to v_in
      # (it also means that join and v_out coincide)
      if old_rev_thread == v_in:
          last = thread[last_succ[u_out]]
      else:
          last = thread[v_in]
  
      # Update _thread and _parent along the stem nodes (i.e. the nodes
      # between u_in and u_out, whose parent have to be changed)
      thread[v_in] = stem = u_in
      dirty_revs = []
      dirty_revs.append(v_in)
      par_stem = v_in
      while stem != u_out:
          # Insert the next stem node into the thread list
          new_stem = parent[stem]
          thread[u] = new_stem
          dirty_revs.append(u)
  
          # Remove the subtree of stem from the thread list
          w = rev_thread[stem]
          thread[w] = right
          rev_thread[right] = w
  
          # Change the parent node and shift stem nodes
          parent[stem] = par_stem
          par_stem = stem
          stem = new_stem
  
          # Update u and right
          if last_succ[stem] == last_succ[par_stem]:
              u = rev_thread[par_stem]
          else:
              u = last_succ[stem]
  
          right = thread[u]
  
      parent[u_out] = par_stem
      thread[u] = last
      rev_thread[last] = u
      last_succ[u_out] = u
  
      # Remove the subtree of u_out from the thread list except for
      # the case when old_rev_thread equals to v_in
      # (it also means that join and v_out coincide)
      if old_rev_thread != v_in:
          thread[old_rev_thread] = right
          rev_thread[right] = old_rev_thread
  
      # Update _rev_thread using the new _thread values
      for i in range(len(dirty_revs)):
          u = dirty_revs[i]
          rev_thread[thread[u]] = u
  
      # Update _pred, _forward, _last_succ and _succ_num for the
      # stem nodes from u_out to u_in
      tmp_sc = 0
      tmp_ls = last_succ[u_out]
      u = u_out
      while u != u_in:
          w = parent[u]
          pred[u] = pred[w]
          forward[u] = not forward[w]
          tmp_sc += succ_num[u] - succ_num[w]
          succ_num[u] = tmp_sc
          last_succ[w] = tmp_ls
          u = w
  
      pred[u_in] = in_arc
      forward[u_in] = u_in == source[in_arc]
      succ_num[u_in] = old_succ_num
  
      # Set limits for updating _last_succ form v_in and v_out
      # towards the root
      up_limit_in = -1
      up_limit_out = -1
      if last_succ[join] == v_in:
          up_limit_out = join
      else:
          up_limit_in = join
  
      # Update _last_succ from v_in towards the root
      u = v_in
      while u != up_limit_in and last_succ[u] == v_in:
          last_succ[u] = last_succ[u_out]
          u = parent[u]
  
      # Update _last_succ from v_out towards the root
      if join != old_rev_thread and v_in != old_rev_thread:
          u = v_out
          while u != up_limit_out and last_succ[u] == old_last_succ:
              last_succ[u] = old_rev_thread
              u = parent[u]
  
      else:
          u = v_out
          while u != up_limit_out and last_succ[u] == old_last_succ:
              last_succ[u] = last_succ[u_out]
              u = parent[u]
  
      # Update _succ_num from v_in to join
      u = v_in
      while u != join:
          succ_num[u] += old_succ_num
          u = parent[u]
  
      # Update _succ_num from v_out to join
      u = v_out
      while u != join:
          succ_num[u] -= old_succ_num
          u = parent[u]
  
imports: import numpy
  import numba
  from collections import namedtuple
  from enum import Enum, IntEnum
label_desc: Use image node_id 6 for calling a global function with example usage: update_spanning_tree(spanning_tree, leaving_arc_data, join, in_arc, source) without return types