并查集压缩路径非递归写法

int find(int x){
    int temp=x;
    while(temp!=d[temp])
        temp=d[temp];
    while(x!=d[x]){
        x=d[x];
        d[x]=temp;
    }
    return temp;
}
原文地址:https://www.cnblogs.com/war1111/p/12526682.html