#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100100;
map<pair<int, int>, long long> path, dp;
int n;
vector<int> v[MAXN];
set<int> processPath[MAXN];
set<int> processDp[MAXN];
set<pair<long long, int>, greater<pair<long long, int> > > bestPath[MAXN];
set<pair<long long, int>, greater<pair<long long, int> > > bestDp[MAXN];
long long a[MAXN];
long long calcPath(int x, int pr) {
  if (path.find(make_pair(x, pr)) != path.end()) {
    return path[make_pair(x, pr)];
  }
  for (auto it = processPath[x].begin(); it != processPath[x].end();) {
    auto nxt = it;
    ++nxt;
    int to = *it;
    if (to == pr) {
      it = nxt;
      continue;
    }
    bestPath[x].insert(make_pair(calcPath(to, x), to));
    processPath[x].erase(to);
    it = nxt;
  }
  long long mx = 0;
  for (auto it = bestPath[x].begin(); it != bestPath[x].end(); ++it) {
    if ((*it).second != pr) {
      mx = (*it).first;
      break;
    }
  }
  path[make_pair(x, pr)] = mx + a[x];
  return path[make_pair(x, pr)];
}
long long calcDp(int x, int pr) {
  if (dp.find(make_pair(x, pr)) != dp.end()) {
    return dp[make_pair(x, pr)];
  }
  for (auto it = processDp[x].begin(); it != processDp[x].end();) {
    auto nxt = it;
    ++nxt;
    int to = *it;
    if (to == pr) {
      it = nxt;
      continue;
    }
    bestDp[x].insert(make_pair(calcDp(to, x), to));
    processDp[x].erase(to);
    it = nxt;
  }
  long long mxDp = 0;
  for (auto it = bestDp[x].begin(); it != bestDp[x].end(); ++it) {
    if ((*it).second != pr) {
      mxDp = (*it).first;
      break;
    }
  }
  long long mxPathA = 0, mxPathB = 0;
  int cnt = 0;
  for (auto it = bestPath[x].begin(); it != bestPath[x].end(); ++it) {
    if (cnt == 2) {
      break;
    }
    if ((*it).second != pr) {
      cnt++;
      if (cnt == 1) {
        mxPathA = (*it).first;
      }
      if (cnt == 2) {
        mxPathB = (*it).first;
      }
    }
  }
  long long mxThr = mxPathA + mxPathB + a[x];
  dp[make_pair(x, pr)] = max(mxDp, mxThr);
  return dp[make_pair(x, pr)];
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%I64d", &a[i]);
  }
  for (int i = 1; i < n; i++) {
    int aa, bb;
    scanf("%d%d", &aa, &bb);
    v[aa].push_back(bb);
    v[bb].push_back(aa);
    processPath[aa].insert(bb);
    processPath[bb].insert(aa);
    processDp[aa].insert(bb);
    processDp[bb].insert(aa);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < v[i].size(); j++) {
      calcPath(i, v[i][j]);
    }
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < v[i].size(); j++) {
      ans = max(ans, calcDp(i, v[i][j]) + calcDp(v[i][j], i));
    }
  }
  cout << ans << endl;
  return 0;
}
