code: def _build_map(outputs):
      """Topologically sort nodes in order from inputs to outputs.
  
      It uses a depth-first search to topologically sort nodes that appear in the
      _keras_history connectivity metadata of `outputs`.
  
      Args:
          outputs: the output tensors whose _keras_history metadata should be
                  walked. This may be an arbitrary nested structure.
  
      Returns:
          A tuple like (ordered_nodes, operation_to_first_traversal_index)
          ordered_nodes: list of nodes appearing in the keras history,
              topologically sorted from original inputs to the `outputs`.
              (If outputs have different sets of ancestors, the inputs to one
              output may appear after a different output).
          operation_to_first_traversal_index:
              A dict mapping operation to the traversal index in the DFS where it
              is seen. Note: if a operation is shared by several nodes, the dict
              will onlystore the index corresponding to the *first* time the
              operation seen.
      """
      finished_nodes = set()
      nodes_in_progress = set()
      nodes_in_decreasing_depth = []  # nodes from inputs -> outputs.
      operation_indices = {}  # operation -> in traversal order.
      for output in tree.flatten(outputs):
          _build_map_helper(
              output,
              finished_nodes,
              nodes_in_progress,
              nodes_in_decreasing_depth,
              operation_indices,
          )
      return nodes_in_decreasing_depth, operation_indices
  
imports: import collections
  import tree
  from keras.api_export import keras_export
  from keras.backend import KerasTensor
  from keras.backend.config import backend
  from keras.ops.operation import Operation
  from keras.utils.nest import pack_sequence_as
label_desc: Use image node_id 3 for calling a global function with example usage: _build_map(outputs) and returns: nodes_in_decreasing_depth,  operation_indices