code: def _depth(g):
      """Computes the number of edges on longest path from node to root."""
  
      def _explore(v):
          if v.depth < 0:
              v.depth = (
                  (
                      1
                      + max(
                          [-1]
                          + [
                              _explore(annotated_graph[u])
                              for u in v.parents
                          ]
                      )
                  )
                  if v.parents
                  else 0
              )
          return v.depth
  
      annotated_graph = {k: _Node(k, v) for k, v in g.items()}
      for v in annotated_graph.values():
          _explore(v)
      return annotated_graph
  
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 1 for calling a global function with example usage: _depth(g) and returns: annotated_graph, v