#include <bits/stdc++.h>
using namespace std;
const long long int N = 1e5 + 5;
const long long int M = 1e3;
const long long int mod = 1e7 + 7;
const long long int m1 = 1e9 + 7;
const long long int m2 = 1e9 + 9;
const long long int p1 = 402653189;
const long long int p2 = 1610612741;
const int LN = 32;
long long int powermodm(long long int x, long long int n, long long int M) {
  long long int result = 1;
  while (n > 0) {
    if (n % 2 == 1) result = (result * x) % M;
    x = (x * x) % M;
    n = n / 2;
  }
  return result;
}
long long int power(long long int _a, long long int _b) {
  long long int _r = 1;
  while (_b) {
    if (_b % 2 == 1) _r = (_r * _a);
    _b /= 2;
    _a = (_a * _a);
  }
  return _r;
}
long long int gcd(long long int a, long long int b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long int lcm(long long int a, long long int b) {
  return (max(a, b) / gcd(a, b)) * min(a, b);
}
long long int dx[4] = {-1, 1, 0, 0};
long long int dy[4] = {0, 0, 1, -1};
long long int pw[LN], fact[N], invfact[N];
void pre() {
  fact[0] = 1;
  for (int i = 0; i < LN; i++) pw[i] = power(2, i);
  for (int i = 1; i < N; i++) fact[i] = (i * fact[i - 1]) % mod;
  for (int i = 0; i < N; i++) invfact[i] = powermodm(fact[i], mod - 2, mod);
}
long long int n, a[N];
vector<long long int> adj[N];
long long int max_down[N], in_sub[N];
long long int max_up[N], out_sub[N], ans;
void dfs(long long int node, long long int par) {
  in_sub[node] = a[node];
  max_down[node] = a[node];
  vector<long long int> in;
  for (auto it : adj[node]) {
    if (it == par) continue;
    dfs(it, node);
    in.push_back(max_down[it]);
    in_sub[node] = max(in_sub[node], in_sub[it]);
    max_down[node] = max(max_down[node], max_down[it] + a[node]);
  }
  if (in.size()) {
    long long int tmp = a[node];
    sort(in.begin(), in.end(), greater<long long int>());
    tmp += in[0];
    if (in.size() > 1) tmp += in[1];
    in_sub[node] = max(in_sub[node], tmp);
  }
}
void solve(long long int node, long long int par, long long int val,
           long long int ending) {
  if (node != 1) ans = max(ans, in_sub[node] + val);
  multiset<long long int> ms_sub, ms_ending;
  ms_ending.insert(ending);
  for (auto it : adj[node]) {
    if (it == par) continue;
    ms_sub.insert(in_sub[it]);
    ms_ending.insert(max_down[it]);
  }
  for (auto it : adj[node]) {
    if (it == par) continue;
    ms_sub.erase(ms_sub.find(in_sub[it]));
    ms_ending.erase(ms_ending.find(max_down[it]));
    long long int subtree = 0, end_tmp = 0;
    if (ms_sub.size()) {
      subtree = *ms_sub.rbegin();
      auto it = ms_ending.end();
      it--;
      end_tmp = *it;
      if (it != ms_ending.begin()) {
        it--;
        end_tmp += *it;
      }
    }
    long long int new_val = max(val, subtree);
    new_val = max(new_val, end_tmp + a[node]);
    solve(it, node, new_val, *(ms_ending.rbegin()) + a[node]);
    ms_sub.insert(in_sub[it]);
    ms_ending.insert(max_down[it]);
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int i, j;
  cin >> n;
  for (i = 1; i <= n; i++) cin >> a[i];
  for (i = 1; i < n; i++) {
    long long int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  dfs(1, 0);
  solve(1, 0, 0, 0);
  cout << ans;
  return 0;
}
