#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 2;
long long inline in() {
  long long x = 0, flag = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') flag = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
  return x * flag;
}
int head[MAXN], nume;
struct Adj {
  int nex, to;
} adj[MAXN << 1];
void addedge(int from, int to) {
  adj[++nume] = (Adj){head[from], to};
  head[from] = nume;
}
void link(int u, int v) {
  addedge(u, v);
  addedge(v, u);
}
int n;
long long a[MAXN];
long long ans[MAXN][3], toleaf[MAXN];
void DFS(int u, int fa) {
  ans[u][0] = ans[u][1] = ans[u][2] = toleaf[u] = a[u];
  long long first = 0, second = 0, mx1 = 0;
  for (int i = head[u]; i; i = adj[i].nex) {
    int v = adj[i].to;
    if (v == fa) continue;
    DFS(v, u);
    ans[u][0] = max(ans[u][0], ans[v][0]);
    ans[u][0] = max(ans[u][0], ans[u][1] + ans[v][1]);
    ans[u][0] =
        max(ans[u][0], max(ans[v][2] + toleaf[u], ans[u][2] + toleaf[v]));
    ans[u][1] = max(ans[u][1], max(toleaf[u] + toleaf[v], ans[v][1]));
    ans[u][2] = max(ans[u][2], ans[v][2] + a[u]);
    ans[u][2] =
        max(ans[u][2], max(toleaf[v] + a[u] + mx1, toleaf[u] + ans[v][1]));
    mx1 = max(mx1, ans[v][1]);
    second = max(second, toleaf[v]);
    if (second > first) swap(second, first);
    toleaf[u] = first + a[u];
  }
}
int main() {
  n = in();
  for (int i = 1; i <= n; ++i) a[i] = in();
  for (int i = 1; i < n; ++i) {
    link(in(), in());
  }
  DFS(1, 0);
  printf("%lld\n", ans[1][0]);
  return 0;
}
