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 |
递归太深了吧In Reply To:为什么我RE了, Posted by:drownever at 2007-07-09 17:08:01 > #include <iostream> > #include <vector> > using namespace std; > int v[100001]; > vector<int> t[100001]; > int first[100001]; > int B[100001]; > > int dfs(int n) > { > if(t[n].size()==0) > return v[n]; > __int64 maxNext=0; > for(__int64 i=0;i<t[n].size();i++) > { > if(B[t[n][i]]==0) B[t[n][i]]=dfs(t[n][i]); > if(maxNext<B[t[n][i]])maxNext=B[t[n][i]]; > } > return v[n]+maxNext; > } > > int main() > { > __int64 n,m; > __int64 max=-999999999; > while(scanf("%I64d %I64d",&n,&m)!=EOF) > { > if(n==1 && m==0) { printf("0\n"); continue; } > > memset(first,0,sizeof(first)); > memset(B,0,sizeof(B)); > memset(t,0,sizeof(t)); > memset(v,0,sizeof(v)); > max=-999999999; > __int64 i,j; > for(i=1;i<=n;i++) scanf("%I64d",&v[i]); > for(i=1;i<=m;i++) > { > __int64 e1,e2; > scanf("%I64d %I64d",&e1,&e2); > first[e2]=1; > t[e1].push_back(e2); > } > for(i=1;i<=n;i++) > if(first[i]==0) > { > if(B[i]==0) B[i]=dfs(i); > if(max<B[i]) > max=B[i]; > } > printf("%I64d\n",max); > } > return 0; > } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator