#include <bits/stdc++.h>
using namespace std;
long long n, c[100005], d1[100005], d2[100005], d3[100005], pos1[100005],
    pos2[100005], pos3[100005], ans;
long long ff1[100005], ff2[100005], fp1[100005], fp2[100005];
vector<long long> edge[100005];
long long dfs(long long v, long long prev) {
  long long mx1 = 0, mx2 = 0, mx3 = 0, ps1 = 0, ps2 = 0, ps3 = 0;
  for (int i = 0; i < edge[v].size(); i++) {
    long long u = edge[v][i];
    if (u == prev) continue;
    long long t = dfs(u, v);
    if (t > mx1)
      mx3 = mx2, ps3 = ps2, mx2 = mx1, ps2 = ps1, mx1 = t, ps1 = u;
    else if (t > mx2)
      mx3 = mx2, ps3 = ps2, mx2 = t, ps2 = u;
    else if (t > mx3)
      mx3 = t, ps3 = u;
  }
  mx1 += c[v], mx2 += c[v], mx3 += c[v];
  d1[v] = mx1;
  d2[v] = mx2;
  d3[v] = mx3;
  pos1[v] = ps1;
  pos2[v] = ps2;
  pos3[v] = ps3;
  return mx1;
}
long long ddd(long long v, long long prev) {
  long long mx1 = 0, mx2 = 0, or1, or2;
  for (int i = 0; i < edge[v].size(); i++) {
    long long u = edge[v][i];
    if (u == prev) continue;
    long long t = ddd(u, v);
    if (mx1 < t)
      mx2 = mx1, or2 = or1, mx1 = t, or1 = u;
    else if (mx2 < t)
      mx2 = t, or2 = u;
  }
  ff1[v] = mx1;
  ff2[v] = mx2;
  fp1[v] = or1;
  fp2[v] = or2;
  return max(mx1, d1[v] + d2[v] - c[v]);
}
long long dfs1(long long v, long long prev, long long up, long long mxup) {
  long long maxx = 0;
  for (int i = 0; i < edge[v].size(); i++) {
    long long u = edge[v][i];
    if (u == prev) continue;
    long long g;
    if (pos1[v] == u) {
      if (fp1[v] == u)
        g = dfs1(u, v, max(up + c[v], d2[v]),
                 max(max(mxup, d2[v] + d3[v] - c[v]), max(up + d2[v], ff2[v])));
      else
        g = dfs1(u, v, max(up + c[v], d2[v]),
                 max(max(mxup, d2[v] + d3[v] - c[v]), max(up + d2[v], ff1[v])));
    } else if (pos2[v] == u) {
      if (fp1[v] == u)
        g = dfs1(u, v, max(up + c[v], d1[v]),
                 max(max(mxup, d1[v] + d3[v] - c[v]), max(ff2[v], up + d1[v])));
      else
        g = dfs1(u, v, max(up + c[v], d1[v]),
                 max(max(mxup, d1[v] + d3[v] - c[v]), max(ff1[v], up + d1[v])));
    } else {
      if (fp1[v] == u)
        g = dfs1(u, v, max(up + c[v], d1[v]),
                 max(max(mxup, d1[v] + d2[v] - c[v]), max(up + d1[v], ff2[v])));
      else
        g = dfs1(u, v, max(up + c[v], d1[v]),
                 max(max(mxup, d1[v] + d2[v] - c[v]), max(up + d1[v], ff1[v])));
    }
    maxx = max(g, maxx);
  }
  ans = max(ans, mxup + max(maxx, d1[v] + d2[v] - c[v]));
  return max(maxx, d1[v] + d2[v] - c[v]);
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> c[i];
  for (int i = 1; i < n; i++) {
    long long x, y;
    cin >> x >> y;
    edge[x].push_back(y);
    edge[y].push_back(x);
  }
  dfs(1, -1);
  ddd(1, -1);
  dfs1(1, -1, 0, 0);
  cout << ans << endl;
  return 0;
}
