虚树

https://blog.csdn.net/weixin_37517391/article/details/82744605

void insert(int u){
    if(top <= 1) {stk[++top] = u;return ;}
    int lca = LCA(u,stk[top]);
    if(lca == stk[top]) {stk[++top] = u;return ;}
    while(top > 1 && dfn[lca] <= stk[top-1]) {
        addedge(stk[top-1],stk[top]);
        --top;
    }
    if(lca != stk[top]) stk[++top] = lca;
    stk[++top] = u;
}

 

posted @ 2021-03-08 13:24  ywwywwyww  阅读(48)  评论(0编辑  收藏  举报