标签:clu rar range stream java arc rip amp integer
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 11261 Accepted Submission(s): 4641
#include<cstdio> #include<cstdlib> #include<cstring> #include<string> #include<algorithm> #include<iostream> #include<queue> #include<map> #include<cmath> #include<set> #include<stack> #define ll long long #define pb push_back #define max(x,y) ((x)>(y)?(x):(y)) #define min(x,y) ((x)>(y)?(y):(x)) #define cls(name,x) memset(name,x,sizeof(name)) using namespace std; const int inf=1e9+10; const ll llinf=1e16+10; const int maxn=6e3+10; const int maxm=1e2+10; const int mod=1e9+7; int n; vector<int> v[maxn]; int dp[maxn][2]; int val[maxn]; int pre[maxn]; void solve(int rt) { dp[rt][1]=val[rt]; dp[rt][0]=0; for(int i=0;i<v[rt].size();i++) { int to=v[rt][i]; solve(to); dp[rt][1]+=dp[to][0]; dp[rt][0]+=max(dp[to][0],dp[to][1]); } } int main() { //freopen("in.txt","r",stdin); while(~scanf("%d",&n)) { for(int i=1;i<=n;i++) scanf("%d",&val[i]); for(int i=1;i<=n;i++) pre[i]=-1; int a,b; for(int i=1;i<=n;i++) v[i].clear(); while(~scanf("%d %d",&a,&b)&&a!=0&&b!=0) { v[b].pb(a); pre[a]=b; } int rt=1; while(pre[rt]!=-1) rt=pre[rt]; solve(rt); printf("%d\n",max(dp[rt][0],dp[rt][1])); } return 0; }
标签:clu rar range stream java arc rip amp integer
原文地址:http://www.cnblogs.com/mgz-/p/7140541.html