#include <bits/stdc++.h>
using namespace std;
int n;
int a[101000];
vector<int> E[101000];
long long dp[101000][4];
void dfs(int u, int fa) {
  long long mx1 = 0;
  long long mx0[3] = {0};
  for (int v : E[u]) {
    if (v == fa) continue;
    dfs(v, u);
    if (dp[v][0] > mx0[0]) {
      mx0[2] = mx0[1], mx0[1] = mx0[0], mx0[0] = dp[v][0];
    } else if (dp[v][0] > mx0[1]) {
      mx0[2] = mx0[1], mx0[1] = dp[v][0];
    } else if (dp[v][0] > mx0[2]) {
      mx0[2] = dp[v][0];
    }
    dp[u][3] = max(dp[u][3], mx1 + dp[v][1]);
    mx1 = max(mx1, dp[v][1]);
  }
  dp[u][0] = mx0[0] + a[u];
  dp[u][1] = max(mx0[0] + mx0[1] + a[u], mx1);
  for (int v : E[u]) {
    if (v == fa) continue;
    long long t1 = dp[v][0] > mx0[1] ? mx0[1] : mx0[0];
    long long t2 = dp[v][0] < mx0[1] ? mx0[1] : mx0[2];
    dp[u][2] = max(dp[u][2], dp[v][2] + a[u]);
    dp[u][2] = max(dp[u][2], dp[v][1] + (t1 + a[u]));
    dp[u][3] = max(dp[u][3], dp[v][3]);
    dp[u][3] = max(dp[u][3], dp[v][2] + a[u] + t1);
    dp[u][3] = max(dp[u][3], dp[v][1] + (t1 + a[u] + t2));
  }
  dp[u][1] = max(dp[u][1], dp[u][0]);
  dp[u][2] = max(dp[u][2], dp[u][1]);
  dp[u][3] = max(dp[u][3], dp[u][2]);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    E[i].clear();
    scanf("%d", a + i);
  }
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    E[u].push_back(v);
    E[v].push_back(u);
  }
  dfs(1, 0);
  printf("%lld\n", dp[1][3]);
  return 0;
}
