def tree_prec_to_adj(prec, root=0):
    """Transforms a tree given as predecessor table into adjacency list form

    :param prec: predecessor table representing a tree, prec[u] == v iff u is descendant 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
    """
    n = len(prec)
    graph = [[prec[u]] for u in range(n)]   # ajouter les prédécesseurs
    graph[root] = []
    for u in range(n):                      # ajouter les descendants
        if u != root:
            graph[prec[u]].append(u)
    return graph