#include<cstdio>
#include<vector>
using namespace std;
vector<int> s[100100];
long long v[100100]={0};
bool vis[100100]={0};
long long f(int x)
{
long long max=v[x],sum=0;
vis[x]=1;
for (int i=0;i<s[x].size();i++)
if (vis[s[x][i]]!=1) sum+=f(i);
if (max<sum) max=sum;
return max;
}
int main()
{
freopen("profitz.in","r",stdin);
freopen("profitz.out","w",stdout);
long long n;
scanf("%d",&n);
for (int i=1;i<=n;i++)
scanf("%d",&v[i]);
int a,b;
for (int i=1;i<n;i++)
{
scanf("%d%d",&a,&b);
s[a].push_back(b);
s[b].push_back(a);
}
long long ans=f(1);
printf("%lld",ans);
}