比赛 |
20151026 |
评测结果 |
AAAAAAAAAA |
题目名称 |
火车站饭店 |
最终得分 |
100 |
用户昵称 |
zhengtn03 |
运行时间 |
0.448 s |
代码语言 |
C++ |
内存使用 |
2.98 MiB |
提交时间 |
2015-10-26 19:36:44 |
显示代码纯文本
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<cmath>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<sstream>
#include<iomanip>
#include<stdlib.h>
using namespace std;
int value1[100010];
vector<int> G[100010];
int choose[100010];
int notchoose[100010];
int used[100010];
void DFS(int point)
{
used[point] = 1;
int temp = 0;
int temp1 = 0;
choose[point] = value1[point];
for (int i = 0; i < G[point].size(); i++)
{
if (used[G[point][i]] == 0)
{
DFS(G[point][i]);
temp = 0;
temp = max(choose[G[point][i]], temp);
temp = max(notchoose[G[point][i]], temp);
notchoose[point] += temp;
choose[point] += notchoose[G[point][i]];
}
}
}
int main()
{
freopen("profitz.in","r",stdin);
freopen("profitz.out","w",stdout);
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++)
{
scanf("%d", value1 + i);
}
for (int i = 0; i < n - 1; i++)
{
int point1, point2;
scanf("%d%d", &point1, &point2);
point1--;
point2--;
G[point1].push_back(point2);
G[point2].push_back(point1);
}
DFS(0);
int ans = 0;
ans = max(choose[0], ans);
ans = max(notchoose[0], ans);
printf("%d\n", ans);
return 0;
}