#include <bits/stdc++.h>
using namespace std;
long long n, hd[200010], nd[400010], nt[400010], t, val[100010], d[100010],
    fa[100010], us[100010], sum[100010];
bool iszj[100010], vis[100010];
void add(long long a, long long b) {
  nd[t] = b;
  nt[t] = hd[a];
  hd[a] = t++;
}
long long bfs(long long x) {
  long long maxn[2] = {-1, 0};
  memset(d, 0, sizeof d);
  memset(fa, 0, sizeof fa);
  queue<long long> que;
  que.push(x);
  d[x] = val[x];
  fa[x] = x;
  while (!que.empty()) {
    long long u = que.front();
    que.pop();
    if (d[u] > maxn[0]) {
      maxn[0] = d[u];
      maxn[1] = u;
    }
    for (long long i = hd[u]; ~i; i = nt[i]) {
      long long v = nd[i];
      if (v == fa[u]) continue;
      fa[v] = u;
      d[v] = d[u] + val[v];
      que.push(v);
    }
  }
  return maxn[1];
}
long long dfs(long long u, long long fa) {
  long long maxn = 0;
  for (long long i = hd[u]; ~i; i = nt[i]) {
    long long v = nd[i];
    if (v == fa || iszj[v]) continue;
    maxn = max(maxn, dfs(v, u) + val[v]);
  }
  return maxn;
}
long long exbfs(long long x) {
  long long maxn[2] = {-1, 0};
  memset(fa, 0, sizeof fa);
  memset(d, 0, sizeof d);
  queue<long long> que;
  que.push(x);
  d[x] = val[x];
  fa[x] = x;
  while (!que.empty()) {
    long long u = que.front();
    que.pop();
    vis[u] = 1;
    if (d[u] > maxn[0]) {
      maxn[0] = d[u];
      maxn[1] = u;
    }
    for (long long i = hd[u]; ~i; i = nt[i]) {
      long long v = nd[i];
      if (v == fa[u] || iszj[v]) continue;
      fa[v] = u;
      d[v] = d[u] + val[v];
      que.push(v);
    }
  }
  return maxn[1];
}
int main() {
  memset(hd, -1, sizeof hd);
  scanf("%lld", &n);
  for (long long i = 1; i <= n; i++) scanf("%lld", &val[i]);
  for (long long i = 1; i < n; i++) {
    long long a, b;
    scanf("%lld%lld", &a, &b);
    add(a, b);
    add(b, a);
  }
  long long sl = bfs(1), tl = bfs(sl), tmp = tl, ti = 0, dq = n + 1, ans = 0,
            fans = d[tl];
  while (1) {
    iszj[tmp] = 1;
    if (fa[tmp] == tmp) break;
    tmp = fa[tmp];
  }
  tmp = tl;
  while (1) {
    ++ti;
    sum[ti] = sum[ti - 1] + val[tmp];
    us[tmp] = dfs(tmp, -1);
    ans = max(1ll * ans,
              max(1ll * us[tmp], 1ll * us[dq] - sum[ti - 1] + us[tmp]));
    us[tmp] += sum[ti];
    if (us[tmp] > us[dq]) dq = tmp;
    if (fa[tmp] == tmp) break;
    tmp = fa[tmp];
  }
  for (long long i = 1; i <= n; i++)
    if (!vis[i] && !iszj[i]) {
      long long a = exbfs(i), b = exbfs(a);
      ans = max(1ll * d[b], ans);
    }
  printf("%lld", fans + ans);
}
