标签:contest ++ span ica iostream problem poj not rate
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 9354 | Accepted: 5400 |
Description
Input
Output
Sample Input
7 1 1 1 1 1 1 1 1 3 2 3 6 4 7 4 4 5 3 5 0 0
Sample Output
5
Source
#include<iostream> #include<cstdio> using namespace std; int n,x,y,rt; int dp[6005][3],dad[6005]; void tree_dp(int now){ for(int i=1;i<=n;i++) if(dad[i]==now){ tree_dp(i); dp[now][1]+=dp[i][0]; dp[now][0]+=max(dp[i][0],dp[i][1]); } } int main(){ scanf("%d",&n); for(int i=1;i<=n;i++)scanf("%d",&dp[i][1]); for(int i=1;i<n;i++)scanf("%d%d",&x,&y),dad[x]=y; rt=n; while(dad[rt])rt=dad[rt]; tree_dp(rt); printf("%d",max(dp[rt][1],dp[rt][0])); return 0; }
标签:contest ++ span ica iostream problem poj not rate
原文地址:http://www.cnblogs.com/zzyh/p/7475878.html