code: def tree_prec_to_adj(prec, root=0):
      
      n = len(prec)
      graph = [[prec[u]] for u in range(n)]   # add predecessors
      graph[root] = []
      for u in range(n):                      # add successors
          if u != root:
              graph[prec[u]].append(u)
      return graph
docs: Transforms a tree given as predecessor table into adjacency list form
  
      :param prec: predecessor table representing a tree, prec[u] == v iff u is successor of v,
                   except for the root where prec[root] == root
      :param root: root vertex of the tree
      :returns: undirected graph in listlist representation
      :complexity: linear