#include <bits/stdc++.h>
using namespace std;
long long int a[100011];
vector<int> g[100011];
long long int up[100011];
long long int best[100011];
long long int ans = 0;
void dfs(int v, int p) {
  long long int max1 = 0, max2 = 0;
  for (auto x : g[v]) {
    if (x != p) {
      dfs(x, v);
      up[v] = max(up[v], up[x]);
      best[v] = max(best[v], best[x]);
      if (up[x] > max1) {
        max2 = max1;
        max1 = up[x];
      } else {
        max2 = max(max2, up[x]);
      }
    }
  }
  up[v] += a[v];
  best[v] = max(best[v], max1 + max2 + a[v]);
  ans = max(ans, best[v]);
}
void solve(int v, int p, long long int upval) {
  vector<int> children;
  for (auto x : g[v]) {
    if (x != p) {
      children.push_back(x);
    }
  }
  if (children.size() == 0) {
    return;
  }
  int C = children.size();
  vector<long long int> prefmax1(C + 2, 0), prefmax2(C + 2, 0),
      sufmax1(C + 2, 0), sufmax2(C + 2, 0), prefbest(C + 2, 0),
      sufbest(C + 2, 0);
  int u;
  for (int i = 1; i <= C; i++) {
    u = children[i - 1];
    prefbest[i] = max(prefbest[i - 1], best[u]);
    prefmax1[i] = prefmax1[i - 1];
    prefmax2[i] = prefmax2[i - 1];
    if (up[u] > prefmax1[i]) {
      prefmax2[i] = prefmax1[i];
      prefmax1[i] = up[u];
    } else {
      prefmax2[i] = max(prefmax2[i], up[u]);
    }
  }
  for (int i = C; i >= 1; i--) {
    u = children[i - 1];
    sufbest[i] = max(sufbest[i + 1], best[u]);
    sufmax1[i] = sufmax1[i + 1];
    sufmax2[i] = sufmax2[i + 1];
    if (up[u] > sufmax1[i]) {
      sufmax2[i] = sufmax1[i];
      sufmax1[i] = up[u];
    } else {
      sufmax2[i] = max(sufmax2[i], up[u]);
    }
  }
  upval += a[v];
  for (int i = 1; i <= C; i++) {
    u = children[i - 1];
    long long int cur = max(prefbest[i - 1], sufbest[i + 1]);
    cur = max(cur, a[v] + prefmax1[i - 1] + sufmax1[i + 1]);
    cur = max(cur, a[v] + prefmax1[i - 1] + prefmax2[i - 1]);
    cur = max(cur, a[v] + sufmax1[i + 1] + sufmax2[i + 1]);
    cur = max(cur, max(prefmax1[i - 1], sufmax1[i + 1]) + upval);
    ans = max(ans, cur + best[u]);
  }
  for (int i = 1; i <= C; i++) {
    u = children[i - 1];
    long long int newupval =
        max(upval, max(prefmax1[i - 1], sufmax1[i + 1]) + a[v]);
    solve(u, v, newupval);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  int n, u, v;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i + 1];
  }
  for (int i = 0; i < n - 1; i++) {
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(1, 0);
  solve(1, 0, 0);
  cout << ans;
}
