Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

无限郁闷的题目。。。难道是我的tarjan模板出问题了,至于这么多TLE的啊。。。求大牛指正模板

Posted by gripleaf at 2011-08-06 14:38:04 on Problem 2762
附我的tarjan模板:
#define Min(a,b) a>b?b:a
#define  M 5010              //题目中可能的最大点数
int STACK[M],top=0;          //Tarjan 算法中的栈
bool InStack[M];             //检查是否在栈中
int DFN[M];                  //深度优先搜索访问次序
int Low[M];                  //能追溯到的最早的次序
int cnt=0;        //有向图强连通分量个数
int Index=0;                 //索引号
vector <int> Edge[M];        //图用邻接表表示
int belong[M];   //记录每个点在第几号强连通分量里//int ComponentDegree[M];     //记录每个强连通分量的度
void Tarjan(int i){
    int j;
    DFN[i]=Low[i]=Index++;
    InStack[i]=true;
    STACK[++top]=i;
    for (int e=0;e<Edge[i].size();e++){
        j=Edge[i][e];
        if (DFN[j]==-1){
            Tarjan(j);
            Low[i]=Min(Low[i],Low[j]);
        }
        else if (InStack[j])
            Low[i]=Min(Low[i],DFN[j]);
    }
    if (DFN[i]==Low[i]){     //因为每一个节点的DFN都是唯一的,所以,当DFN[i]=Low[i]时,即又回到原先的点
        cnt++;//强连通分量的个数或者说是序号
        do{
            j=STACK[top--];
            InStack[j]=false;
            belong[j]=cnt;
        }while(j!=i);
    }
}
void solve(){
    memset(STACK,-1,sizeof(STACK));
    memset(InStack,0,sizeof(InStack));
    memset(DFN,-1,sizeof(DFN));
    memset(Low,-1,sizeof(Low));
    for(int i=0;i<N;i++)
        if(DFN[i]==-1)       Tarjan(i);
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator