#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 79;
vector<long long> dpa(maxn, 0), dpa1(maxn, 0), dpa1b(maxn, 0), dpa2b(maxn, 0),
    dpab(maxn, 0);
vector<long long> a;
vector<vector<int> > g;
inline void upd(long long& t, const long long& v) { t = max(t, v); }
void dfsdp(int v, int p = -1) {
  dpa[v] = dpa1[v] = dpa1b[v] = dpa2b[v] = dpab[v] = a[v];
  vector<long long> maxi(3, 0);
  for (int u : g[v]) {
    if (u == p) continue;
    dfsdp(u, v);
    maxi.push_back(dpa1[u]);
    sort(maxi.begin(), maxi.end(), greater<long long>());
    while (maxi.size() > 3) maxi.pop_back();
  }
  long long maxa = 0;
  for (int u : g[v]) {
    if (u == p) continue;
    long long mymax = (dpa1[u] == maxi[0] ? maxi[1] : maxi[0]);
    upd(dpa1[v], dpa1[u] + a[v]);
    upd(dpa[v], dpa[u]);
    upd(dpa[v], mymax + dpa1[u] + a[v]);
    upd(dpa1b[v], dpa1b[u] + a[v]);
    upd(dpa1b[v], dpa[u] + mymax + a[v]);
    upd(dpa2b[v], dpa2b[u] + a[v]);
    if (mymax) upd(dpa2b[v], dpa[u] + mymax + a[v]);
    upd(dpab[v], dpa1b[u] + mymax + a[v]);
    upd(dpab[v], dpa2b[u] + mymax + a[v]);
    long long twomax = maxi[0] + maxi[1] + maxi[2] - max(dpa1[u], maxi[2]);
    upd(dpab[v], dpa[u] + twomax + a[v]);
    upd(dpab[v], dpa[u] + maxa);
    upd(maxa, dpa[u]);
  }
}
int main() {
  int n;
  cin >> n;
  a.resize(n);
  g.resize(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  int nonleaf = -1;
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    g[--a].push_back(--b);
    g[b].push_back(a);
    if (g[a].size() > 1) nonleaf = a;
    if (g[b].size() > 1) nonleaf = b;
  }
  if (n == 2) {
    cout << a[0] + a[1] << "\n";
    return 0;
  }
  dfsdp(nonleaf);
  cout << *max_element(dpab.begin(), dpab.end()) << "\n";
  return 0;
}
