def extract_path(prec, v):
    """extracts a path in form of vertex list from source to vertex v
       given a precedence table prec leading to the source

    :param prec: precedence table of a tree
    :param v: vertex on the tree
    :returns: path from root to v, in form of a list
    :complexity: linear
    """
    L = []
    while v is not None:
        L.append(v)
        v = prec[v]
        assert v not in L   # prevent infinite loops for a bad formed table prec
    return L[::-1]