tarjan(人工栈)

void tarjan(int y){
	bool flag;
	tops=top=0;
	ss[++tops]=y;
	while (tops){
		flag=0;
		int x=ss[tops];
		if (!dfn[x]) {
			dfn[x]=low[x]=++num;
			cur[x]=head1[x];
			s[++top]=x;
			vis[x]=1;
		}
		Fo1(i,x){
			int v=to1[i];		
			if (!dfn[v]){
				ss[++tops]=v;
				flag=1;
				cur[x]=next1[i];
				break;
			}
			else 
				if (vis[v]) low[x]=min(low[x],dfn[v]);
		}
		if (flag) continue;
		if (low[x]==dfn[x]){
			++sum;
			do{
				vis[s[top]]=0;
				cnt[s[top]]=sum;
				bz[sum]|=pd[s[top]];
				d[sum]+=val[s[top]];
				if (s[top]==s1) s2=sum; 
				top--;
			}while (x!=s[top+1]);
		}
		low[ss[--tops]]=min(low[ss[tops]],low[x]);
	}
}

你可能感兴趣的:(模板,taran)