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

C++ 56ms,G++ RE,why?

Posted by zehzxm at 2007-09-23 13:56:18 on Problem 3256
#include <iostream>
#include <vector>
using namespace std;

vector<vector<int> > vec(1010);
int dat[110],sum;

int tim[1010];
bool visit[1010];

void dfs(int idx)
{
    tim[idx]++;visit[idx]=true;
    int i,num=vec[idx].size();
    for(i=0;i<num;i++)
    {
        if(!visit[vec[idx][i]]) dfs(vec[idx][i]);
    }
}    

int main()
{
    int i,j,k,n,m,a,b;
    scanf("%d%d%d",&k,&n,&m);
    {
        vec.clear();sum=0;
        memset(tim,0,sizeof(tim));
        for(i=0;i<k;i++)
            scanf("%d",&dat[i]);
        for(i=0;i<m;i++)
        {
            scanf("%d%d",&a,&b);
            vec[a].push_back(b);
        }    
        for(i=0;i<k;i++)
        {
            memset(visit,false,sizeof(visit));
            dfs(dat[i]);
        }   
        for(i=1;i<=n;i++) if(tim[i]==k) sum++;
        printf("%d\n",sum);   
    }    
}    

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