【图论】倍增与lca

void dfs(long u,long father){
dep[u]=dep[father]+1;//只在这里初始化dep
 
for(long i=1;(1<=0;i--){//跳到同一个深度
    if(dep[fa[x][i]]>=dep[y])x=fa[x][i];
    if(x==y)return x;
}
 
for(int i=20;i>=0;i--){
    if(fa[x][i]!=fa[y][i]){//一起跳
        x=fa[x][i];
        y=fa[y][i];
    }
}
return fa[x][0];
}

提单1
题单2

Head out to the Target

你可能感兴趣的:(图论,算法)