#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void chkmax(T& x, U y) {
  if (x < y) x = y;
}
template <typename T, typename U>
inline void chkmin(T& x, U y) {
  if (y < x) x = y;
}
int n;
vector<int> con[123456];
long long dp[2][123456], dia[123456], res, d[2][123456], d1[123456];
vector<long long> V;
int a[123456];
void DFS(int u, int par) {
  dp[0][u] = a[u];
  dp[1][u] = -1;
  d[0][u] = d[1][u] = -1;
  for (int i = 0; i < con[u].size(); i++) {
    int v = con[u][i];
    if (v == par) continue;
    DFS(v, u);
    if (dp[0][u] < dp[0][v] + a[u]) {
      dp[1][u] = dp[0][u], dp[0][u] = dp[0][v] + a[u];
    } else if (dp[0][u] == dp[0][v] + a[u]) {
      dp[1][u] = dp[0][u];
    } else {
      chkmax(dp[1][u], dp[0][v] + a[u]);
    }
    if (d[0][u] < dia[v]) {
      d[1][u] = d[0][u], d[0][u] = dia[v];
    } else if (d[0][u] == dia[v]) {
      d[1][u] = dia[v];
    } else {
      chkmax(d[1][u], dia[v]);
    }
  }
  V.clear();
  for (int i = 0; i < con[u].size(); i++) {
    int v = con[u][i];
    if (v == par) continue;
    V.push_back(dp[0][v] + a[u]);
  }
  dia[u] = d[0][u];
  chkmax(dia[u], dp[0][u]);
  if (dp[1][u] >= 0) chkmax(dia[u], dp[0][u] + dp[1][u] - a[u]);
  sort((V).begin(), (V).end());
  reverse((V).begin(), (V).end());
  for (int i = 0; i < con[u].size(); i++) {
    int v = con[u][i];
    if (v == par) continue;
    if (V.size() <= 2) {
      d1[v] = -1;
      continue;
    } else {
      if (dp[0][v] + a[u] == V[0]) {
        d1[v] = V[1] + V[2] - a[u];
      } else if (dp[0][v] + a[u] == V[1]) {
        d1[v] = V[0] + V[2] - a[u];
      } else
        d1[v] = V[0] + V[1] - a[u];
    }
  }
}
long long dd[123456], deep[123456];
void solve(int u, int par) {
  for (int i = 0; i < con[u].size(); i++) {
    int v = con[u][i];
    if (v == par) continue;
    long long tmp = dd[u];
    long long x;
    if (dp[0][v] == dp[0][u] - a[u])
      x = dp[1][u];
    else
      x = dp[0][u];
    if (dia[v] == d[0][u])
      chkmax(tmp, d[1][u]);
    else
      chkmax(tmp, d[0][u]);
    chkmax(tmp, d1[v]);
    tmp = max(max(0LL, x) + deep[u], tmp);
    chkmax(res, tmp + dia[v]);
    dd[v] = max(max(x - a[u], deep[u]) + a[u], tmp);
    deep[v] = max(x - a[u], deep[u]) + a[u];
    solve(v, u);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i <= n; i++) con[i].clear();
  for (int i = 0; i < n; i++) scanf("%d", a + i);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    u--, v--;
    con[u].push_back(v);
    con[v].push_back(u);
  }
  DFS(0, 0);
  res = 0;
  solve(0, 0);
  cout << res << endl;
  return 0;
}
