def UFFind(UFP, u):
    """
    Union find "find" with path-compression
    :param UFP: A list of pointers to reprsentative nodes
    :param u: Index of the node to find
    :return: Index of the representative of the component of u
    """
    if not (UFP[u] == u):
        UFP[u] = UFFind(UFP, UFP[u])
    return UFP[u]