警示后人
查看原帖
警示后人
828664
Llx2022楼主2023/9/5 10:04
int LCA(int u,int v){
    while(top[u]!=top[v]){
        if(dep[top[u]]<dep[top[v]]) swap(u,v);
        u=father[top[u]];
    }
    if(dep[u]>dep[v]) swap(u,v);
    return u;
}

树剖千万别写挂了,这么写是对的。

int LCA(int u,int v){
    while(top[u]!=top[v]){
        if(dep[u]<dep[v]) swap(u,v);
        u=father[top[u]];
    }
    if(dep[u]>dep[v]) swap(u,v);
    return u;
}

底下这么写就是错的

2023/9/5 10:04
加载中...