#include <bits/stdc++.h>
using namespace std;
const long long N = 100005;
vector<long long> e[N];
long long a[N], dp[N][5], ans;
void dfs(long long u, long long fa) {
  dp[u][0] = a[u];
  dp[u][1] = a[u];
  dp[u][2] = a[u];
  dp[u][3] = a[u];
  for (auto v : e[u]) {
    if (v == fa) continue;
    dfs(v, u);
    dp[u][0] = max(dp[u][0], dp[v][0]);
    dp[u][0] = max(dp[u][0], dp[u][1] + dp[v][1]);
    dp[u][0] = max(dp[u][0], dp[u][2] + dp[v][3]);
    dp[u][0] = max(dp[u][0], dp[v][2] + dp[u][3]);
    dp[u][1] = max(dp[u][1], dp[v][1]);
    dp[u][1] = max(dp[u][1], dp[u][3] + dp[v][3]);
    dp[u][2] = max(dp[u][2], dp[v][2] + a[u]);
    dp[u][2] = max(dp[u][2], dp[u][3] + dp[v][1]);
    dp[u][2] = max(dp[u][2], dp[v][3] + a[u] + dp[u][4]);
    dp[u][4] = max(dp[u][4], dp[v][1]);
    dp[u][3] = max(dp[u][3], dp[v][3] + a[u]);
  }
}
int main() {
  long long n;
  scanf("%lld", &n);
  for (long long i = 1; i <= n; ++i) scanf("%lld", &a[i]);
  for (long long i = 2; i <= n; ++i) {
    long long x, y;
    scanf("%lld%lld", &x, &y);
    e[x].push_back(y);
    e[y].push_back(x);
  }
  dfs(1, 0);
  printf("%lld\n", dp[1][0]);
  return 0;
}
