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 |
求大神看看 DAG错哪里了#include <iostream> #include <cstdio> #include <cstring> #include <vector> #include <climits> using namespace std; int n,m,a[100001],d[100001]; bool cc[100001]; vector<int> b[100001]; int solve(int i) { if(d[i] != INT_MIN) return d[i]; d[i] = a[i]; for(int j=0;j<b[i].size();++j) d[i] = max(d[i],a[i]+solve(b[i][j])); return d[i]; } int main() { while(scanf("%d %d",&n,&m) != EOF) { for(int i=1;i<=n;++i) scanf("%d",&a[i]); a[0] = 0; int x,y; for(int i=0;i<=n;++i) { b[i].clear(); d[i] = INT_MIN; cc[i] = false; } for(int i=1;i<=m;++i) { scanf("%d %d",&x,&y); b[x].push_back(y); cc[y] = true; } for(int i=1;i<=n;++i) if(b[i].size()!=0&&!cc[i]) b[0].push_back(i); printf("%d\n",solve(0)); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator