#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
long long f[maxn][3], g[maxn][3];
int s[maxn];
vector<int> G[maxn];
void add_edge(int u, int v) {
  G[u].push_back(v);
  G[v].push_back(u);
}
void get_max(long long& x, long long y) {
  if (y > x) x = y;
}
void dfs(int u, int fa) {
  long long a[3][3] = {0};
  long long b[3][3] = {0};
  long long c[3][3] = {0};
  for (auto v : G[u]) {
    if (v == fa) continue;
    dfs(v, u);
    memset(b, 0, sizeof(b));
    memset(c, 0, sizeof(c));
    for (int i = 0; i <= 2; i++) b[i][0] = f[v][i];
    for (int i = 0; i <= 2; i++) b[i][1] = g[v][i];
    for (int x = 0; x <= 2; x++)
      for (int y = 0; x + y <= 2; y++)
        for (int p = 0; p <= 2; p++)
          for (int q = 0; p + q <= 2; q++) {
            get_max(c[x + y][p + q], a[x][p] + b[y][q]);
          }
    memcpy(a, c, sizeof(c));
  }
  for (int i = 1; i <= 2; i++)
    for (int j = 0; j <= 2; j++) get_max(f[u][i], a[i - 1][j] + s[u]);
  for (int i = 0; i <= 2; i++)
    for (int j = 0; j <= 1; j++) get_max(g[u][i], a[i][j] + s[u]);
  for (int i = 0; i <= 2; i++) get_max(f[u][i], a[i][0]);
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &s[i]);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    add_edge(u, v);
  }
  dfs(1, -1);
  cout << f[1][2] << '\n';
  return 0;
}
