void tarjan(int x){
low[x]=dfn[x]=++num;
s[++top]=x;
v[x]=1;
for(int i=head[x];i;i=nex[i]){
int y=e[i];
if(!dfn[y]){
tarjan(y);
low[x]=min(low[x],low[y]);
}
else if(v[y])
low[x]=min(low[x],dfn[y]);
}
if(low[x]==dfn[x]){
cnt++;
do{
int y=s[top];
p[y]=cnt;
siz[cnt]++;
v[y]=0;
}while(x!=s[top--]);
}
}
tarjan有向图缩点
猜你喜欢
转载自blog.csdn.net/Fooooooo/article/details/104908140
今日推荐
周排行