模板—v-dcc缩点
作者:互联网
int dfn[MAXN],low[MAXN],num,root; int stack[MAXN],top,cnt; bool iscut[MAXN]; int new_id[MAXN],c[MAXN]; vector<int> dcc[MAXN]; void tarjan(int x) { dfn[x]=low[x]=++num; stack[++top]=x; if(x==root&&!f(x)){dcc[++cnt].push_back(x);return;} int flag=0; for(int i=f(x);i;i=n(i)) if(!dfn[v(i)]) { tarjan(v(i));low[x]=min(low[x],low[v(i)]); if(low[v(i)]>=dfn[x]) { flag++; if(x!=root||flag>1)iscut[x]=1; cnt++;int z; do{dcc[cnt].push_back(z=stack[top--]);}while(z!=v(i)); dcc[cnt].push_back(x); } } else low[x]=min(low[x],dfn[v(i)]); } signed main() { for(int i=1;i<=n;i++) if(!dfn[i]){root=i;tarjan(i);} num=cnt; for(int i=1;i<=n;i++) if(iscut[i])new_id[i]=++num; for(int i=1;i<=cnt;i++) for(int j=0;j<dcc[i].size();j++) { int x=dcc[i][j]; if(iscut[x]) add2(i,new_id[x]),add2(new_id[x],i); else c[dcc[i][j]]=i; } }
标签:缩点,cnt,int,dcc,dfn,MAXN,low,模板 来源: https://www.cnblogs.com/Al-Ca/p/11181829.html