深入解析:【图论】倍增与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

posted @ 2025-07-27 20:34  yjbjingcha  阅读(6)  评论(0)    收藏  举报