#include <bits/stdc++.h>
using namespace std;
int mod1 = int(1e9) + 7;
long long a[100100];
vector<int> e[100100];
unordered_map<int, pair<long long, long long>> tag[100100];
vector<int> degx, deg1, deg0;
int deg[100100];
multiset<long long> topbound[100100], topfree[100100];
void prop(int x, int y) {
  if (tag[y][x] != make_pair(0LL, 0LL)) {
    topbound[x].erase(tag[y][x].first);
    topfree[x].erase(tag[y][x].second);
  }
  long long tb = a[x];
  if (topbound[x].size() > 0) {
    tb += *topbound[x].rbegin();
  }
  long long tf = a[x];
  if (topfree[x].size() > 0) {
    tf = max(tf, *topfree[x].rbegin());
  }
  if (topbound[x].size() > 0) {
    auto it = topbound[x].rbegin();
    tf = max(tf, *it + a[x]);
  }
  if (topbound[x].size() > 1) {
    auto it = topbound[x].rbegin();
    tf = max(tf, *it + *(++it) + a[x]);
  }
  tag[x][y] = make_pair(tb, tf);
  deg[y]--;
  if (deg[y] == 1) deg1.push_back(y);
  if (deg[y] == 0) deg0.push_back(y);
  topbound[y].insert(tb);
  topfree[y].insert(tf);
  if (tag[y][x] != make_pair(0LL, 0LL)) {
    topbound[x].insert(tag[y][x].first);
    topfree[x].insert(tag[y][x].second);
  }
}
int main() {
  int n;
  scanf("%d", &(n));
  for (int i = 1; i <= (int)(n); ++i) scanf("%lld", &a[i]);
  for (int i = 1; i <= (int)(n - 1); ++i) {
    int a, b;
    scanf("%d%d", &(a), &(b));
    e[a].push_back(b);
    e[b].push_back(a);
  }
  for (int i = 1; i <= (int)(n); ++i) degx.push_back(i);
  for (int i = 1; i <= (int)(n); ++i) deg[i] = e[i].size();
  for (int i = 0; i < (int)(n); ++i) {
    if (deg[i] == 1) deg1.push_back(i);
  }
  while (true) {
    if (!deg0.empty()) {
      int x = deg0.back();
      deg0.pop_back();
      for (int i = 0; i < (int)(e[x].size()); ++i) {
        int y = e[x][i];
        if (tag[x][y] == make_pair(0LL, 0LL)) {
          prop(x, y);
        }
      }
    } else if (!deg1.empty()) {
      int x = deg1.back();
      deg1.pop_back();
      for (int i = 0; i < (int)(e[x].size()); ++i) {
        int y = e[x][i];
        if (tag[y][x] == make_pair(0LL, 0LL)) {
          prop(x, y);
          break;
        }
      }
    } else
      break;
  }
  long long mmax = 0;
  for (int x = 1; x <= (int)(n); ++x) {
    for (int i = 0; i < (int)(e[x].size()); ++i) {
      int y = e[x][i];
      long long c = tag[x][y].second + tag[y][x].second;
      mmax = max(mmax, c);
    }
  }
  printf(
      "%lld"
      "\n",
      mmax);
  return 0;
}
