def find_parent(lst, i, dist):
    """Finds the parent node of the given node in a pre-order traversal list.

    Args:
        lst: a list that contains a pre-order traversal of a free-tree
        i: the index of the actual node
        dist: the distance of the actual node

    Returns:
        int: the index of the node's parent (-1 if it has no parent)
    """
    while i >= 0:
        if lst[i] < dist:
            break
        i -= 1
    return i