#include <bits/stdc++.h>
using namespace std;
const int mm = 1e5 + 5;
int n;
long long re = 0;
long long a[mm], h[mm], f[mm];
vector<int> e[mm];
struct ii {
  long long gt;
  int vt;
};
void khoitao(ii ma[5][5]) {
  for (int i = 1; i <= 2; i++)
    for (int j = 1; j <= 3; j++) ma[i][j] = {-1, -1};
}
void capnhat1(ii ma[5][5], long long x, int y) {
  if (ma[1][1].gt < x) {
    ma[1][2] = ma[1][1];
    ma[1][1] = {x, y};
  } else if (ma[1][2].gt < x)
    ma[1][2] = {x, y};
}
void capnhat2(ii ma[5][5], long long x, int y) {
  if (ma[2][1].gt < x) {
    ma[2][3] = ma[2][2];
    ma[2][2] = ma[2][1];
    ma[2][1] = {x, y};
  } else if (ma[2][2].gt < x) {
    ma[2][3] = ma[2][2];
    ma[2][2] = {x, y};
  } else if (ma[2][3].gt < x)
    ma[2][3] = {x, y};
}
void Dfs(int u, int p) {
  ii ma[5][5];
  khoitao(ma);
  f[u] = h[u] = a[u];
  for (int v : e[u]) {
    if (v == p) continue;
    Dfs(v, u);
    f[u] = max(f[u], f[v]);
    h[u] = max(h[u], h[v] + a[u]);
    capnhat2(ma, h[v], v);
  }
  long long s = 0;
  for (int i = 1; i <= 2; i++) {
    if (ma[2][i].gt == -1) break;
    s += ma[2][i].gt;
  }
  f[u] = max(f[u], s + a[u]);
}
void dfs(int u, int p, long long fmax, long long hmax) {
  ii ma[5][5];
  khoitao(ma);
  re = max(re, f[u] + fmax);
  capnhat1(ma, fmax, -1);
  capnhat2(ma, hmax, -1);
  for (int v : e[u]) {
    if (v == p) continue;
    capnhat1(ma, f[v], v);
    capnhat2(ma, h[v], v);
  }
  for (int v : e[u]) {
    if (v == p) continue;
    long long ftam = 0, htam = 0, s = 0;
    int d = 0;
    if (ma[1][1].vt != v)
      ftam = ma[1][1].gt;
    else
      ftam = ma[1][2].gt;
    if (ma[2][1].vt != v)
      htam = ma[2][1].gt;
    else
      htam = ma[2][2].gt;
    for (int i = 1; i <= 3; i++) {
      if (ma[2][i].vt == v) continue;
      if (ma[2][i].gt == -1) continue;
      d++;
      s += ma[2][i].gt;
      if (d == 2) break;
    }
    dfs(v, u, max(ftam, s + a[u]), htam + a[u]);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
  for (int i = 1; i <= n - 1; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    e[x].push_back(y);
    e[y].push_back(x);
  }
  Dfs(1, 0);
  dfs(1, 0, 0, 0);
  printf("%lld ", re);
}
