code: def _best_order(g):
      """Creates tuple of str tuple-str pairs representing resolved & sorted DAG."""
      if isinstance(g, collections.OrderedDict):
          return g.items()
  
      def _explore(u):
          """Recursive function to ascend up through unvisited dependencies."""
          if u.depth < 0:
              return  # Already visited.
          if not u.parents:
              result.append((u.name, u.parents))
              u.depth = -1  # Mark visited.
              return
          u.depth = -1  # Mark visited.
          for v in sorted(
              (g.get(p) for p in u.parents),
              key=lambda v: (v.depth, v.name),
              reverse=True,
          ):
              _explore(v)
          result.append((u.name, u.parents))
  
      g = _depth(g)
      result = []
      for u in sorted(
          g.values(), key=lambda v: (v.depth, v.name), reverse=True
      ):
          _explore(u)
      return tuple(result)
  
imports: import collections
  import functools
  import tensorflow.compat.v2
  from tensorflow_probability.python.distributions import joint_distribution_sequential
  from tensorflow_probability.python.internal import auto_composite_tensor
  from tensorflow_probability.python.internal import distribution_util
label_desc: Use image node_id 2 for calling a global function with example usage: _best_order(g) and returns: tuple, g