#include <bits/stdc++.h>
using namespace std;
int n;
long long val[100100];
vector<int> adj[100100];
long long bst[100100];
long long dp[100100];
long long dp2[100100];
void merge(long long a, long long b, long long c, long long d, long long &_1,
           long long &_2) {
  _1 = a;
  _2 = b;
  _2 = max(_2, c);
  if (_1 < _2) {
    swap(_2, _1);
  }
  _2 = max(_2, d);
  if (_1 < _2) {
    swap(_2, _1);
  }
}
void dfs(int nd, int p) {
  long long mx1 = 0, mx2 = 0;
  dp[nd] = -1ll << 60;
  for (int i = 0; i < adj[nd].size(); i++) {
    int ch = adj[nd][i];
    if (ch == p) continue;
    dfs(ch, nd);
    bst[nd] = max(bst[nd], bst[ch]);
    mx2 = max(mx2, bst[ch]);
    dp[nd] = max(dp[nd], dp[ch]);
    if (mx1 < mx2) {
      swap(mx1, mx2);
    }
  }
  bst[nd] += val[nd];
  dp[nd] = max(dp[nd], mx1 + mx2 + val[nd]);
}
void dfs2(int nd, int p, long long leg, long long bb) {
  dp2[nd] = bb;
  vector<long long> bstL(adj[nd].size()), bstL2(adj[nd].size()),
      bstR(adj[nd].size()), bstR2(adj[nd].size()), btL(adj[nd].size()),
      btR(adj[nd].size());
  for (int i = 0; i < adj[nd].size(); i++) {
    bstL[i] = bstL2[i] = bstR[i] = bstR2[i] = btL[i] = btR[i] = 0;
  }
  for (int i = 0; i < adj[nd].size(); i++) {
    int ch = adj[nd][i];
    if (i > 0) {
      bstL[i] = bstL[i - 1];
      bstL2[i] = bstL2[i - 1];
      btL[i] = btL[i - 1];
    } else {
      bstL[i] = 0;
      bstL2[i] = 0;
      btL[i] = 0;
    }
    if (ch == p) continue;
    btL[i] = max(btL[i], dp[ch]);
    bstL2[i] = max(bstL2[i], bst[ch]);
    if (bstL2[i] > bstL[i]) {
      swap(bstL2[i], bstL[i]);
    }
  }
  for (int i = adj[nd].size() - 1; i >= 0; i--) {
    int ch = adj[nd][i];
    if (i < adj[nd].size() - 1) {
      bstR[i] = bstR[i + 1];
      btR[i] = btR[i + 1];
      bstR2[i] = bstR2[i + 1];
    } else {
      bstR[i] = 0;
      btR[i] = 0;
      bstR2[i] = 0;
    }
    if (ch == p) continue;
    btR[i] = max(btR[i], dp[ch]);
    bstR2[i] = max(bstR2[i], bst[ch]);
    if (bstR2[i] > bstR[i]) {
      swap(bstR2[i], bstR[i]);
    }
  }
  for (int i = 0; i < adj[nd].size(); i++) {
    int ch = adj[nd][i];
    if (ch == p) continue;
    long long _1, _2;
    long long a = 0, b = 0, c = 0, d = 0;
    long long gg = -1ll << 60;
    if (i > 0) {
      a = bstL[i - 1];
      b = bstL2[i - 1];
      gg = btL[i - 1];
    }
    if (i < adj[nd].size() - 1) {
      c = bstR[i + 1];
      d = bstR2[i + 1];
      gg = max(gg, btR[i + 1]);
    }
    merge(a, b, c, d, _1, _2);
    _2 = max(_2, leg);
    if (_2 > _1) {
      swap(_2, _1);
    }
    dfs2(ch, nd, _1 + val[nd], max(max(gg, bb), _1 + _2 + val[nd]));
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &val[i]);
  }
  for (int i = 2; i <= n; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  dfs(1, 1);
  dfs2(1, 1, 0, -1ll << 60);
  long long sol = 0;
  for (int i = 1; i <= n; i++) {
    sol = max(sol, dp[i] + dp2[i]);
  }
  cout << sol << endl;
}
