#include<bits/stdc++.h>
using namespace std;
const int N = 20000;
int head[N], idx;
int n, f[N];
bool vis[N];
struct tTree{
int to, pre;
} edge[N];
void ade(int,int);
void dfs(int);
int main(){
cin >> n;
for (int i = 1; i <= n; ++i)
cin >> f[i];
for (int i = 1; i <= n-1; ++i){
int a, b;
cin >> a >> b;
ade(a,b); ade(b,a);
}
dfs(1);
int ans = 0xafafafaf;
for (int i = 1; i <= n; ++i)
ans = max(ans,f[i]);
cout << ans;
return 0;
}
void ade(int u, int v){
edge[++idx].pre = head[u];
edge[idx].to = v;
head[u] = idx;
}
void dfs(int u){
vis[u] = true;
for (int i = head[u]; i; i = edge[i].pre){
int v = edge[i].to;
if (!vis[v]){
dfs(v);
f[u] = max(f[u],f[u]+f[v]);
}
}
}