#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e5 + 5;
long long n, a[maxn], dp[maxn][2], f[maxn][2], d[maxn];
long long head[maxn], ecnt;
struct edge {
  long long to, next;
} e[maxn << 1];
void adde(long long u, long long v) {
  e[++ecnt].to = v;
  e[ecnt].next = head[u];
  head[u] = ecnt;
}
long long read() {
  long long res = 0, f = 1;
  char ch;
  do {
    ch = getchar();
    if (ch == '-') f = -1;
  } while (!isdigit(ch));
  do {
    res = res * 10 + ch - '0';
    ch = getchar();
  } while (isdigit(ch));
  return res * f;
}
void dfs1(long long u, long long fa) {
  dp[u][0] = dp[u][1] = f[u][0] = d[u] = a[u];
  for (long long i = head[u]; i; i = e[i].next) {
    long long v = e[i].to;
    if (v == fa) continue;
    dfs1(v, u);
    dp[u][0] = max(dp[u][0], dp[v][0]);
    dp[u][0] = max(dp[u][0], dp[u][1] + dp[v][1]);
    dp[u][0] = max(dp[u][0], d[u] + f[v][0]);
    dp[u][0] = max(dp[u][0], d[v] + f[u][0]);
    dp[u][1] = max(dp[u][1], dp[v][1]);
    dp[u][1] = max(dp[u][1], d[u] + d[v]);
    f[u][0] = max(f[u][0], a[u] + f[v][0]);
    f[u][0] = max(f[u][0], d[u] + dp[v][1]);
    f[u][0] = max(f[u][0], a[u] + d[v] + f[u][1]);
    f[u][1] = max(f[u][1], dp[v][1]);
    d[u] = max(d[u], d[v] + a[u]);
  }
}
signed main() {
  n = read();
  for (long long i = (1); i <= (n); ++i) a[i] = read();
  for (long long i = (1); i <= (n - 1); ++i) {
    long long u = read(), v = read();
    adde(u, v);
    adde(v, u);
  }
  dfs1(1, 0);
  printf("%lld\n", dp[1][0]);
}
