#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int SUM = 0, ff = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') ff = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    SUM = (SUM << 3) + (SUM << 1) + (ch ^ 48);
    ch = getchar();
  }
  return SUM * ff;
}
const int N = 100010;
struct edge {
  int nxt, to;
} e[N << 1];
int h[N], cnte = 1;
inline void addedge(int u, int v) { e[++cnte] = (edge){h[u], v}, h[u] = cnte; }
int w[N], n;
long long f[N][2], g[N], maxv[N], down[N];
inline void dfs(int u, int fu) {
  f[u][0] = w[u];
  f[u][1] = w[u];
  g[u] = w[u];
  maxv[u] = 0;
  down[u] = w[u];
  for (int i = h[u]; i; i = e[i].nxt) {
    int v = e[i].to;
    if (v == fu) continue;
    dfs(v, u);
    f[u][0] = max(f[u][0], f[v][0]);
    f[u][0] = max(f[u][0], f[u][1] + f[v][1]);
    f[u][0] = max(f[u][0], down[u] + g[v]);
    f[u][0] = max(f[u][0], g[u] + down[v]);
    f[u][1] = max(f[u][1], f[v][1]);
    f[u][1] = max(f[u][1], down[u] + down[v]);
    g[u] = max(g[u], w[u] + g[v]);
    g[u] = max(g[u], down[u] + f[v][1]);
    g[u] = max(g[u], down[v] + w[u] + maxv[u]);
    maxv[u] = max(maxv[u], f[v][1]);
    down[u] = max(down[u], down[v] + w[u]);
  }
}
int main() {
  n = read();
  for (int i = 1; i <= n; i++) w[i] = read();
  for (int i = 1; i <= n - 1; i++) {
    int u = read(), v = read();
    addedge(u, v), addedge(v, u);
  }
  dfs(1, 0);
  printf("%lld\n", f[1][0]);
  return 0;
}
