tarjan

#define M 10010
int STACK[M],top=0;
int DFN[M],LOW[M],Index=0;
bool InStack[M];
int cnumber=0;
vector <int> Edge[M];
vector <int> C[M];
int Inc[M],cD[M];
void tarjan(int i){
    int j;
    Index++;
    DFN[i]=LOW[i]=Index;
    InStack[i]=true;
    STACK[++top]=i;
    for(long unsigned int e=0;e<Edge[i].size();e++){
        j=Edge[i][e];
        if(DFN[j]==-1){
            tarjan(j);
            LOW[i]=min(LOW[j],LOW[i]);
        }
        else {
            if(InStack[j]) LOW[i]=min(LOW[i],DFN[j]);
         }    
        }
        if(DFN[i]==LOW[i]){
            cnumber++;
            do{
                j=STACK[top--];
                InStack[j]=false;
                C[cnumber].push_back(j);
                Inc[j]=cnumber;
            }while(i!=j);
        }
         

}

 

posted @ 2018-10-28 11:11  uncklesam7  阅读(146)  评论(0编辑  收藏  举报