#include <bits/stdc++.h>
using namespace std;
int he[100005], np;
int n;
long long v[100005], f2[100005], fl[100005], ms[100005];
long long h[100005], g[100005];
int read() {
  int x = 0;
  char ch;
  ch = getchar();
  while (ch < '0' || ch > '9') ch = getchar();
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x;
}
struct edg {
  int to, nxt;
} e[200005];
void ad(int x, int y) {
  np++;
  e[np].to = y;
  e[np].nxt = he[x];
  he[x] = np;
}
void dfs(int x, int fa) {
  f2[x] = fl[x] = ms[x] = g[x] = v[x];
  for (int i = he[x]; i; i = e[i].nxt) {
    int y = e[i].to;
    if (y == fa) continue;
    dfs(y, x);
    f2[x] = max(f2[x], f2[y]);
    f2[x] = max(f2[x], g[x] + ms[y]);
    f2[x] = max(f2[x], ms[x] + g[y]);
    f2[x] = max(f2[x], fl[x] + fl[y]);
    fl[x] = max(fl[x], ms[x] + ms[y]);
    fl[x] = max(fl[x], fl[y]);
    g[x] = max(g[x], v[x] + g[y]);
    g[x] = max(g[x], ms[y] + v[x] + h[x]);
    g[x] = max(g[x], ms[x] + fl[y]);
    h[x] = max(h[x], fl[y]);
    ms[x] = max(ms[x], v[x] + ms[y]);
  }
}
int main() {
  n = read();
  for (int i = 1; i <= n; i++) {
    v[i] = read();
  }
  for (int i = 1; i <= n - 1; i++) {
    int x = read(), y = read();
    ad(x, y);
    ad(y, x);
  }
  dfs(1, 0);
  cout << f2[1];
  return 0;
}
