code: def maximum_spanning_arborescence(
      G, attr="weight", default=1, preserve_attrs=False, partition=None
  ):
      # In order to use the same algorithm is the maximum branching, we need to adjust
      # the weights of the graph. The branching algorithm can choose to not include an
      # edge if it doesn't help find a branching, mainly triggered by edges with negative
      # weights.
      #
      # To prevent this from happening while trying to find a spanning arborescence, we
      # just have to tweak the edge weights so that they are all positive and cannot
      # become negative during the branching algorithm, find the maximum branching and
      # then return them to their original values.
  
      min_weight = INF
      max_weight = -INF
      for _, _, w in G.edges(data=attr):
          if w < min_weight:
              min_weight = w
          if w > max_weight:
              max_weight = w
  
      for _, _, d in G.edges(data=True):
          d[attr] = d[attr] - min_weight + 1 - (min_weight - max_weight)
  
      B = maximum_branching(G, attr, default, preserve_attrs, partition)
  
      for _, _, d in G.edges(data=True):
          d[attr] = d[attr] + min_weight - 1 + (min_weight - max_weight)
  
      for _, _, d in B.edges(data=True):
          d[attr] = d[attr] + min_weight - 1 + (min_weight - max_weight)
  
      if not is_arborescence(B):
          raise nx.exception.NetworkXException(
              "No maximum spanning arborescence in G."
          )
  
      return B
  
imports: import string
  from dataclasses import dataclass, field
  from enum import Enum
  from operator import itemgetter
  from queue import PriorityQueue
  import networkx
  from networkx.utils import py_random_state
  from .recognition import is_arborescence, is_branching
label_desc: Use image node_id 10 for calling a global function with example usage: maximum_spanning_arborescence(G, attr, default, preserve_attrs, partition) and returns: B