#include <bits/stdc++.h>
using namespace std;
long long const N = 1e5 + 20;
long long n, choc[N], mx[N], irmx[N], upmx[N], ans;
vector<long long> adj[N];
void ins(long long k, long long &a, long long &b, long long &c) {
  if (k > c) c = k;
  if (c > b) swap(b, c);
  if (b > a) swap(a, b);
  return;
}
void dfs1(long long v, long long par = -1) {
  long long a = 0, b = 0;
  for (auto u : adj[v]) {
    if (u != par) {
      dfs1(u, v);
      mx[v] = max(mx[v], mx[u]);
      irmx[v] = max(irmx[v], irmx[u]);
      b = max(b, irmx[u]);
      if (b > a) swap(a, b);
    }
  }
  irmx[v] += choc[v];
  mx[v] = max(mx[v], a + b + choc[v]);
  return;
}
void dfs2(long long v, long long par = -1) {
  long long a = 0, b = 0;
  if (!v) upmx[v] = choc[v];
  a = upmx[v];
  for (auto u : adj[v]) {
    if (u != par) {
      b = max(b, irmx[u] + choc[v]);
      if (b > a) swap(a, b);
    }
  }
  for (auto u : adj[v]) {
    if (u != par) {
      if (irmx[u] + choc[v] == a)
        upmx[u] = b + choc[u];
      else
        upmx[u] = a + choc[u];
      dfs2(u, v);
    }
  }
  return;
}
void dfs3(long long v, long long par = -1) {
  long long a = upmx[v] - choc[v], b = 0, c = 0;
  long long MX = 0;
  for (auto u : adj[v]) {
    if (u != par) {
      dfs3(u, v);
      ins(irmx[u], a, b, c);
      ans = max(ans, MX + mx[u]);
      MX = max(MX, mx[u]);
    }
  }
  for (auto u : adj[v]) {
    if (u != par) {
      if (irmx[u] == a)
        ans = max(ans, b + c + choc[v] + mx[u]);
      else if (irmx[u] == b)
        ans = max(ans, a + c + choc[v] + mx[u]);
      else
        ans = max(ans, a + b + choc[v] + mx[u]);
    }
  }
  return;
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (long long i = 0; i < n; i++) cin >> choc[i];
  for (long long i = 0; i < n - 1; i++) {
    long long x, y;
    cin >> x >> y;
    x--, y--;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  dfs1(0);
  dfs2(0);
  dfs3(0);
  return cout << ans, 0;
}
