int root=1; int belong[MAXN],tot; int dfn[MAXN],low[MAXN],num; int stack[MAXN],top; bool instack[MAXN]; void tarjan(int u,int fa){ dfn[u]=low[u]=++num; stack[++top]=u; instack[u]=true; int tto; for(int i=head[u];i;i=bl[i].inext){ if(bl[i].to==fa)continue; if(!dfn[tto=bl[i].to]){ tarjan(tto,u); low[u]=minn(low[u],low[tto]); } else low[u]=minn(dfn[tto],low[u]); } if(low[u]==dfn[u]){ int tan=stack[top]; ++tot; while(tan!=u){ belong[tan]=tot; instack[tan]=false; tan=stack[--top]; } --top; belong[u]=tot; instack[u]=false; } return ; }
tarjan无向图缩点
猜你喜欢
转载自www.cnblogs.com/2018hzoicyf/p/11182977.html
今日推荐
周排行