#include <bits/stdc++.h>
using namespace std;
const int N = 500101;
vector<int> e[N];
int v[N];
int a, b, n, i;
long long ans, f[N], g[N], h[N];
void dfs(int x, int fa) {
  int i;
  long long tmp = 0, tmp1 = v[x], tmp2 = v[x];
  f[x] = g[x] = h[x] = v[x];
  long long t1, t2, t3;
  int p1, p2, p3;
  t1 = t2 = t3 = v[x];
  p1 = p2 = p3 = x;
  for (i = 0; i < e[x].size(); i++)
    if (e[x][i] != fa) {
      dfs(e[x][i], x);
      if (tmp + g[e[x][i]] > ans) ans = tmp + g[e[x][i]];
      tmp = max(tmp, g[e[x][i]]);
      g[x] = max(g[x], g[e[x][i]]);
      g[x] = max(g[x], f[x] + f[e[x][i]]);
      f[x] = max(f[x], f[e[x][i]] + v[x]);
      h[x] = max(h[x], h[e[x][i]] + v[x]);
      ans = max(ans, h[e[x][i]] + tmp1);
      ans = max(ans, f[e[x][i]] + tmp2);
      tmp1 = max(tmp1, f[x]);
      tmp2 = max(tmp2, h[x]);
      if (f[e[x][i]] + v[x] > t1) {
        t3 = t2;
        p3 = p2;
        t2 = t1;
        p2 = p1;
        t1 = f[e[x][i]] + v[x];
        p1 = e[x][i];
      } else if (f[e[x][i]] + v[x] > t2) {
        t3 = t2;
        p3 = p2;
        t2 = f[e[x][i]] + v[x];
        p2 = e[x][i];
      } else if (f[e[x][i]] + v[x] > t3) {
        t3 = f[e[x][i]] + v[x];
        p3 = e[x][i];
      }
    }
  ans = max(ans, g[x]);
  for (i = 0; i < e[x].size(); i++)
    if (e[x][i] != fa) {
      if (e[x][i] == p1)
        h[x] = max(h[x], g[e[x][i]] + t2);
      else
        h[x] = max(h[x], g[e[x][i]] + t1);
      if (e[x][i] == p1)
        ans = max(ans, t2 + t3 - v[x] + g[e[x][i]]);
      else if (e[x][i] == p2)
        ans = max(ans, t1 + t3 - v[x] + g[e[x][i]]);
      else
        ans = max(ans, t1 + t2 - v[x] + g[e[x][i]]);
    }
}
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &v[i]);
  for (i = 1; i < n; i++) {
    scanf("%d%d", &a, &b);
    e[a].push_back(b);
    e[b].push_back(a);
  }
  dfs(1, 0);
  printf("%I64d\n", ans);
}
