模板—tarjan缩点

void tarjan(int x)
{
    dfn[x]=++cnt;low[x]=cnt;
    vi[x]=1;
    stack[++top]=x;
    for(rint i=f(x);i;i=n(i))
        if(!dfn[v(i)])tarjan(v(i)),low[x]=min(low[x],low[v(i)]);
        else if(vi[v(i)])low[x]=min(low[x],low[v(i)]);
    if(dfn[x]==low[x])
    {
        tot++;vi[x]=0;ooo=0;
        while(stack[top]!=x)
        {
            belong[stack[top]]=tot;
            scc[tot].push_back(stack[top]);
            vi[stack[top--]]=0;
        }
        scc[tot].push_back(stack[top]);
        belong[stack[top--]]=tot;
    }
}
signed main()
{
    for(rint i=1;i<=num_e;i++)
        if(belong[u(i)]!=belong[v(i)])
            add2(belong[u(i)],belong[v(i)]),du[belong[v(i)]]++;
}

 

posted @ 2019-07-12 17:05  Al_Ca  阅读(132)  评论(0编辑  收藏  举报
ヾ(≧O≦)〃嗷~