标签:main arch stdin stack seq max miss contain rate
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 8028 | Accepted: 4594 |
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
1 #include <iostream> 2 #include <cstdio> 3 #include <vector> 4 #include <queue> 5 #include <map> 6 #include <cmath> 7 #include <stack> 8 #include <cstring> 9 #include <algorithm> 10 #include <cstdlib> 11 #define FOR(i,x,n) for(long i=x;i<n;i++) 12 #define ll long long int 13 #define INF 0x3f3f3f3f 14 #define MOD 1000000007 15 #define MAX_N 60 16 #define MAX_M 1005 17 18 using namespace std; 19 20 struct node{ 21 int number; 22 int rating; 23 int sonNum; 24 int son[500]; 25 int father; 26 }; 27 node tree[6005]; 28 //int visable[6005]; 29 int dp[6005][2];//0表示不去,1表示去 30 31 void dfs(int root){ 32 FOR(i,0,tree[root].sonNum){ 33 dfs(tree[root].son[i]); 34 dp[root][0]+=max(dp[tree[root].son[i]][0],dp[tree[root].son[i]][1]); 35 dp[root][1]+=dp[tree[root].son[i]][0]; 36 } 37 } 38 39 int main() 40 { 41 //freopen("input1.txt", "r", stdin); 42 //freopen("data.out", "w", stdout); 43 int n; 44 //memset(visable,0,sizeof(visable)); 45 memset(dp,0,sizeof(dp)); 46 scanf("%d",&n); 47 FOR(i,1,n+1){ 48 tree[i].father=i; 49 tree[i].sonNum=0; 50 } 51 FOR(i,1,n+1){ 52 scanf("%d",&dp[i][1]); 53 } 54 int t1,t2; 55 FOR(i,0,n){ 56 scanf("%d %d",&t1,&t2); 57 if(!(t1+t2)){ 58 break; 59 } 60 tree[t1].father=t2; 61 tree[t2].son[tree[t2].sonNum++]=t1; 62 } 63 int t=1; 64 while(tree[t].father!=t){ 65 t=tree[t].father; 66 } 67 dfs(t); 68 printf("%d",max(dp[t][0],dp[t][1])); 69 //fclose(stdin); 70 //fclose(stdout); 71 return 0; 72 }
标签:main arch stdin stack seq max miss contain rate
原文地址:http://www.cnblogs.com/TWS-YIFEI/p/6653010.html