def __init__(self,parent):
        """Construct LCA structure from tree parent relation."""
        children = {}
        for x in parent:
            children.setdefault(parent[x],[]).append(x)
        root = [x for x in children if x not in parent]
        if len(root) != 1:
            raise ValueError("LCA input is not a tree")
 
        levels = []
        self._representatives = {}
        self._visit(children,levels,root[0],0)
        if [x for x in parent if x not in self._representatives]:
            raise ValueError("LCA input is not a tree")
        self._rangemin = _RestrictedRangeMin(levels)
Construct LCA structure from tree parent relation.
recipes/Python/252123_Range_minimleast/recipe-252123.py