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

帮忙看看阿!!WA了好多了次!!

Posted by edison979 at 2008-04-04 12:32:14 on Problem 1144
#include <cstdlib>
#include <iostream>
using namespace std;

const int define=101;
int low[define],vi[define],A[define][define],label[define];
int cnode=0;
int judge(int n);
void Dfs(int v,int n);
 
int main(void)
{
    int n=0,total=0,a=0,i=0,j=0,num=0,len=0;
    char B[define];
    while(cin>>n&&n){
        memset(low,0,sizeof(low));
        memset(vi,0,sizeof(vi));
        memset(A,0,sizeof(A));
        memset(label,0,sizeof(label));       
        total=0;
        cnode=0;
        getchar();
        for(i=1;i<=n;i++){  //处理输入数据 
            j=num=0;
            gets(B);
            len=strlen(B);
            if(len==1&&B[0]=='0') break;
            while(B[j]!=' '){
                num=num*10+(B[j]-48);
                j++;
            }
            for(j++;j<len;j++)          
                if(B[j]!=' '){
                    a=0;
                    while(B[j]!=' '&&j<len){
                        a=a*10+(B[j]-48);
                        j++;
                    }                  
                    A[num][a]=A[a][num]=1;
                }   
        }
        vi[1]=++cnode;
        low[1]=1;     
        for(i=1;i<=n;i++)
            if(A[1][i]==1) break;  //对第一个节点的第一个分支节点开始深度搜索 
        Dfs(i,n); 
        if(cnode<n){  //cnode表示访问了多少个节点 
            label[1]=1; 
            for(i=1;i<=n;i++)
                if(A[1][i]==1&&vi[i]==0)
                    Dfs(i,n);                              
        }
        for(i=1;i<=n;i++)
            if(label[i]==1) total++;    
        cout<<total<<endl; 
    }
    return 0;
}

void Dfs(int v,int n)  //n represent the total nodes number
{
    int i=0,min=0; 
    vi[v]=min=++cnode;// vi表示访问顺序 
    for(i=1;i<=n;i++)
        if(A[v][i]==1){            
            if(vi[i]==0){
                Dfs(i,n);                           
                if(low[i]<min) min=low[i];
                if(low[i]>=vi[v])                  
                    label[v]=1;                          
            } 
            else if(vi[i]<min)
                min=vi[i];                                 
        } 
    low[v]=min; 
} 

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