#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
int n, a[maxn];
long long dp[maxn][3][3];
vector<int> E[maxn];
void deal(int x, int v) {
  for (int i = 2; i >= 0; i--) {
    for (int j = 2; j >= 0; j--) {
      for (int k = 0; k < 3 - i; k++) {
        for (int l = 0; l < 3 - j; l++) {
          if (l != 2) {
            if (j == 0 && l == 1)
              dp[x][i + k][j + l] =
                  max(dp[x][i + k][j + l], dp[x][i][j] + dp[v][k][l] + a[x]);
            else
              dp[x][i + k][j + l] =
                  max(dp[x][i + k][j + l], dp[x][i][j] + dp[v][k][l]);
          }
        }
      }
    }
  }
}
void dfs(int x, int fa) {
  dp[x][0][1] = a[x];
  for (int i = 0; i < E[x].size(); i++) {
    int v = E[x][i];
    if (fa == v) continue;
    dfs(v, x);
    deal(x, v);
  }
  dp[x][1][0] = max(dp[x][1][0], dp[x][0][2]);
  dp[x][1][0] = max(dp[x][1][0], dp[x][0][1]);
  dp[x][2][0] = max(dp[x][2][0], dp[x][1][2]);
  dp[x][2][0] = max(dp[x][2][0], dp[x][1][1]);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    E[x].push_back(y);
    E[y].push_back(x);
  }
  dfs(1, -1);
  long long ans = 0;
  ans = max(dp[1][0][0], dp[1][0][1]);
  ans = max(ans, max(dp[1][1][0], dp[1][1][1]));
  ans = max(dp[1][2][0], ans);
  printf("%lld\n", ans);
}
