code: def _minimum_rooted_branching(D, root):
      """Helper function to compute a minimum rooted branching (aka rooted
      arborescence)
  
      Before the branching can be computed, the directed graph must be rooted by
      removing the predecessors of root.
  
      A branching / arborescence of rooted graph G is a subgraph that contains a
      directed path from the root to every other vertex. It is the directed
      analog of the minimum spanning tree problem.
  
      References
      ----------
      [1] Khuller, Samir (2002) Advanced Algorithms Lecture 24 Notes.
      https://web.archive.org/web/20121030033722/https://www.cs.umd.edu/class/spring2011/cmsc651/lec07.pdf
      """
      rooted = D.copy()
      # root the graph by removing all predecessors to `root`.
      rooted.remove_edges_from(
          [(u, root) for u in D.predecessors(root)]
      )
      # Then compute the branching / arborescence.
      A = nx.minimum_spanning_arborescence(rooted)
      return A
  
imports: import itertools
  import math
  from collections import defaultdict, namedtuple
  import networkx
  from networkx.utils import not_implemented_for, py_random_state
label_desc: Use image node_id 14 for calling a global function with example usage: _minimum_rooted_branching(D, root) and returns: A