#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100100;
long long a[MAXN];
vector<int> g[MAXN];
long long d[MAXN];
int id[MAXN][4];
long long h[MAXN][4];
vector<pair<long long, long long> > di[MAXN];
bool mk[MAXN];
int root;
void dfs(int u, int p) {
  for (int i = 0; i < 3; i++) {
    id[u][i] = -1;
    h[u][i] = 0;
  }
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i];
    if (v != p) {
      dfs(v, u);
      di[u].push_back(pair<long long, long long>(d[v], i));
      d[u] = max(d[u], d[v]);
      id[u][3] = v;
      h[u][3] = h[v][0] + a[v];
      for (int i = 3; i > 0; i--) {
        if (h[u][i - 1] <= h[u][i]) {
          swap(h[u][i - 1], h[u][i]);
          swap(id[u][i - 1], id[u][i]);
        }
      }
    }
  }
  if (di[u].size() > 0) {
    sort(di[u].begin(), di[u].end());
  }
  d[u] = max(d[u], h[u][0] + h[u][1] + a[u]);
}
long long outp;
void solve(int u, int p, long long hh, long long dupp) {
  outp = max(outp, d[u] + dupp);
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i];
    if (v != p) {
      long long dup = dupp;
      if (i != di[u][di[u].size() - 1].second) {
        dup = max(dup, di[u][di[u].size() - 1].first);
      } else if (di[u].size() > 1) {
        dup = max(dup, di[u][di[u].size() - 2].first);
      }
      if (id[u][0] == v) {
        solve(v, u, max(hh, h[u][1]) + a[u],
              max(dup, h[u][1] + max(h[u][2], hh) + a[u]));
      } else if (id[u][1] == v) {
        solve(v, u, max(hh, h[u][0]) + a[u],
              max(dup, h[u][0] + max(h[u][2], hh) + a[u]));
      } else {
        solve(v, u, max(hh, h[u][0]) + a[u],
              max(dup, h[u][0] + max(h[u][1], hh) + a[u]));
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  root = 1;
  dfs(root, -1);
  outp = 0ll;
  solve(root, -1, 0ll, 0ll);
  cout << outp << '\n';
}
