#include <bits/stdc++.h>
int N, head[100001], next[199999], to[199999], E, q[100001], fa[100001];
long long w[100001], f0[100001], f1[100001], g0[100001], g1[100001];
inline void cover(long long &x, long long &y, long long z) {
  if (z > x)
    y = x, x = z;
  else if (z > y)
    y = z;
}
inline void cover(long long &x, long long &y, long long &z, long long w) {
  if (w > x)
    z = y, y = x, x = w;
  else if (w > y)
    z = y, y = w;
  else if (w > z)
    z = w;
}
int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) scanf("%lld", w + i);
  for (int i = 1, u, v; i < N; i++) {
    scanf("%d%d", &u, &v);
    next[++E] = head[u], to[E] = v, head[u] = E;
    next[++E] = head[v], to[E] = u, head[v] = E;
  }
  int H = 0, T = 1, u;
  q[1] = 1;
  while (H < T)
    for (int e = head[u = q[++H]]; e; e = next[e])
      if (to[e] != fa[u]) fa[q[++T] = to[e]] = u;
  for (int i = N; i; i--) {
    int u = q[i];
    long long f0_0 = 0, f0_1 = 0, f0_2 = 0;
    for (int e = head[u]; e; e = next[e])
      if (to[e] != fa[u]) {
        cover(f0_0, f0_1, f0_2, f0[to[e]]);
        g0[u] = std::max(g0[u], g0[to[e]]);
      }
    f0[u] = f0_0 + w[u];
    g0[u] = std::max(g0[u], f0_0 + f0_1 + w[u]);
    for (int e = head[u]; e; e = next[e])
      if (to[e] != fa[u])
        f1[u] = std::max(
            f1[u],
            std::max(g0[to[e]] + (f0_0 == f0[to[e]] ? f0_1 : f0_0), f1[to[e]]));
    f1[u] += w[u];
    long long g0_0 = 0, g0_1 = 0;
    for (int e = head[u]; e; e = next[e])
      if (to[e] != fa[u]) {
        cover(g0_0, g0_1, g0[to[e]]);
        g1[u] = std::max(g1[u], g1[to[e]]);
      }
    g1[u] = std::max(g1[u], g0_0 + g0_1);
    for (int e = head[u]; e; e = next[e])
      if (to[e] != fa[u])
        g1[u] = std::max(
            g1[u],
            w[u] +
                std::max(f1[to[e]] + (f0[to[e]] == f0_0 ? f0_1 : f0_0),
                         g0[to[e]] + (f0_0 == f0[to[e]] ? f0_1 : f0_0) +
                             (f0_0 == f0[to[e]] || f0_1 == f0[to[e]] ? f0_2
                                                                     : f0_1)));
  }
  printf("%lld\n", std::max(std::max(f0[1], f1[1]), std::max(g0[1], g1[1])));
  return 0;
}
