#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
struct node {
  int y, next;
} b[N << 1];
int n, m, k, s, t, v[N], head[N], tot;
long long f[N][2], ans;
void add(int s, int t) {
  b[++tot].y = t;
  b[tot].next = head[s];
  head[s] = tot;
}
void dfs(int x, int fa) {
  long long k1 = 0, k2 = 0;
  for (int k = head[x]; k; k = b[k].next) {
    int y = b[k].y;
    if (y != fa) {
      dfs(y, x);
      f[x][0] = max(f[x][0], f[y][0]);
      if (f[y][1] >= k1) {
        k2 = k1;
        k1 = f[y][1];
      } else if (f[y][1] > k2)
        k2 = f[y][1];
    }
  }
  f[x][0] = max(f[x][0], k1 + k2 + v[x]);
  f[x][1] = v[x] + k1;
}
void dfs1(int x, int fa) {
  long long k1 = 0, k2 = 0, p1 = 0, p2 = 0, p3 = 0;
  long long x1 = f[x][0], x2 = f[x][1];
  for (int k = head[x]; k; k = b[k].next) {
    int y = b[k].y;
    if (f[y][0] >= k1) {
      k2 = k1;
      k1 = f[y][0];
    } else if (f[y][0] > k2)
      k2 = f[y][0];
    if (f[y][1] >= p1) {
      p3 = p2;
      p2 = p1;
      p1 = f[y][1];
    } else if (f[y][1] >= p2) {
      p3 = p2;
      p2 = f[y][1];
    } else if (f[y][1] > p3)
      p3 = f[y][1];
  }
  for (int k = head[x]; k; k = b[k].next) {
    int y = b[k].y;
    if (y != fa) {
      if (f[y][0] == k1)
        f[x][0] = k2;
      else
        f[x][0] = k1;
      if (f[y][1] == p1) {
        f[x][0] = max(f[x][0], p2 + p3 + v[x]);
        f[x][1] = p2 + v[x];
      } else if (f[y][1] == p2) {
        f[x][0] = max(f[x][0], p1 + p3 + v[x]);
        f[x][1] = p1 + v[x];
      } else {
        f[x][0] = max(f[x][0], p1 + p2 + v[x]);
        f[x][1] = p1 + v[x];
      }
      ans = max(ans, f[y][0] + f[x][0]);
      dfs1(y, x);
    }
  }
  f[x][0] = x1;
  f[x][1] = x2;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> v[i];
  for (int i = 1; i < n; ++i) {
    cin >> s >> t;
    add(s, t);
    add(t, s);
  }
  dfs(1, 0);
  dfs1(1, 0);
  cout << ans;
}
