Tarjan shrink entry point

Point reduction

As the name suggests, it is to a condensation point strongly connected components shrink to a point

Tarjan

Recorded timestamp of dfs process, if the point can return traversed by a point, the point may be reduced

inline void Tarjan(int x)// st栈,low当前可已过的时间戳最大的,dfn当前点的时间戳,co当前点属于的强连通分量
{
    low[x]=dfn[x]=++cnt;
    st[++top]=x,vis[x]=1;
    for(re int i=h[x];i;i=e[i].ne)
    {
        int y=e[i].to;
        if(!dfn[y])
        {
            Tarjan(y);
            low[x]=min(low[x],low[y]);
        }
        else if(vis[y])
            low[x]=min(low[x],dfn[y]);
    }
    if(low[x]==dfn[x])
    {
        ++color;
        while(st[top+1]!=x)
        {
            co[st[top]]=color;
            ww[color]+=w[st[top]];
            vv[color]+=v[st[top]];
            vis[st[top--]]=0;
        }
    }
}

Guess you like

Origin www.cnblogs.com/yzhx/p/11325586.html