#include <bits/stdc++.h>
using namespace std;
char _;
const long long maxN = 100 * 1000 + 5;
const long long mod = 1000 * 1000 * 1000 + 7;
const long long base = 701;
const long long SQ = 500;
const long long maxL = 20;
vector<long long> a[maxN];
long long dp[maxN], bes[maxN];
long long st[maxN], en[maxN], cnt;
long long val[maxN];
void dfs(long long v, long long par = -1) {
  st[v] = cnt++;
  vector<long long> tt;
  for (auto u : a[v]) {
    if (u - par) {
      dfs(u, v);
      dp[v] = max(dp[v], dp[u]);
      tt.push_back(dp[u]);
      sort(tt.rbegin(), tt.rend());
      if (tt.size() > 2) tt.pop_back();
    }
  }
  dp[v] += val[v];
  bes[v] = val[v];
  for (auto it : tt) bes[v] += it;
  en[v] = cnt;
}
long long gg[maxN], seg[4 * maxN];
void build(long long s, long long e, long long id) {
  if (e - s == 1) {
    seg[id] = gg[s];
    return;
  }
  long long mid = (s + e) >> 1;
  build(s, mid, 2 * id);
  build(mid, e, 2 * id + 1);
  seg[id] = max(seg[2 * id], seg[2 * id + 1]);
}
long long get(long long l, long long r, long long s, long long e,
              long long id) {
  if (l >= e || r <= s) return 0;
  if (l <= s && e <= r) return seg[id];
  long long mid = (s + e) >> 1;
  return max(get(l, r, s, mid, 2 * id), get(l, r, mid, e, 2 * id + 1));
}
long long n;
long long ans;
long long D[maxN];
void DFS(long long v, long long par = -1) {
  vector<pair<long long, long long> > tt;
  tt.push_back({D[v], -1});
  for (auto u : a[v])
    if (u - par) {
      tt.push_back({dp[u] + val[v], u});
      sort(tt.rbegin(), tt.rend());
      if (tt.size() > 3) tt.pop_back();
    }
  for (auto u : a[v])
    if (u - par) {
      for (long long i = 0; i < (long long)tt.size(); i++)
        if (tt[i].second != u) {
          D[u] = tt[i].first + val[u];
          break;
        }
      long long bes = 0, ted = 0;
      for (long long i = 0; i < (long long)tt.size(); i++)
        if (tt[i].second != u) {
          bes += tt[i].first;
          ted++;
          if (ted == 2) break;
        }
      bes -= val[v];
      ans = max(ans, bes + get(st[u], en[u], 0, n, 1));
      DFS(u, v);
    }
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (long long i = 0; i < n; i++) cin >> val[i];
  for (long long i = 1; i < n; i++) {
    long long v, u;
    cin >> v >> u;
    v--;
    u--;
    a[v].push_back(u);
    a[u].push_back(v);
  }
  dfs(0);
  for (long long i = 0; i < n; i++) gg[st[i]] = bes[i];
  build(0, n, 1);
  for (long long i = 0; i < n; i++) {
    long long tmp = bes[i] + get(en[i], n, 0, n, 1);
    ans = max(ans, tmp);
  }
  D[0] = val[0];
  DFS(0);
  cout << ans << endl;
  return 0;
}
