code: def tree_adj_to_prec(graph, root=0):
      
      prec = [None] * len(graph)
      prec[root] = root            # mark to visit root only once
      to_visit = [root]
      while to_visit:              # DFS
          node = to_visit.pop()
          for neighbor in graph[node]:
              if prec[neighbor] is None:
                  prec[neighbor] = node
                  to_visit.append(neighbor)
      prec[root] = None            # put the standard mark for root
      return prec
docs: Transforms a tree given as adjacency list into predecessor table form.
      if graph is not a tree: will return a DFS spanning tree
  
      :param graph: directed graph in listlist or listdict format
      :returns: tree in predecessor table representation
      :complexity: linear