Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
C++ 56ms,G++ RE,why?#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator