#include <bits/stdc++.h>
using namespace std;
const int MAXN = (int)1E5 + 10;
int n;
long long ans;
int a[MAXN], p[MAXN], child[MAXN];
long long c[MAXN], d[MAXN], lp[MAXN], dp[MAXN];
vector<int> e[MAXN];
stack<int> st, rst;
void dfs1() {
  st.push(1);
  while (!st.empty()) {
    int u = st.top();
    st.pop();
    for (auto v : e[u])
      if (v != p[u]) {
        child[u]++;
        p[v] = u;
        st.push(v);
      }
    if (child[u] == 0) rst.push(u);
  }
  while (!rst.empty()) {
    int u = rst.top();
    rst.pop();
    long long s1 = 0, s2 = 0;
    for (auto v : e[u])
      if (v != p[u]) {
        if (c[v] > s1) {
          s2 = s1;
          s1 = c[v];
        } else
          s2 = max(s2, c[v]);
        d[u] = max(d[u], d[v]);
      }
    d[u] = max(d[u], s1 + s2 + a[u]);
    c[u] = s1 + a[u];
    child[p[u]]--;
    if (!child[p[u]]) rst.push(p[u]);
  }
}
void dfs2() {
  st.push(1);
  while (!st.empty()) {
    int u = st.top();
    st.pop();
    long long s1 = 0, s2 = 0, s3 = 0, d1 = dp[u], d2 = dp[u];
    for (auto v : e[u])
      if (v != p[u]) {
        if (c[v] > s1) {
          s3 = s2;
          s2 = s1;
          s1 = c[v];
        } else if (c[v] > s2) {
          s3 = s2;
          s2 = c[v];
        } else
          s3 = max(s3, c[v]);
        if (d[v] > d1) {
          d2 = d1;
          d1 = d[v];
        } else
          d2 = max(d2, d[v]);
      }
    for (auto v : e[u])
      if (v != p[u]) {
        if (c[v] == s1) {
          lp[v] = max(lp[u], s2) + a[u];
          dp[v] = s2 + max(lp[u], s3) + a[u];
          if (d[v] == d1)
            dp[v] = max(dp[v], d2);
          else
            dp[v] = max(dp[v], d1);
        } else {
          lp[v] = max(lp[u], s1) + a[u];
          if (c[v] == s2)
            dp[v] = max(dp[u], s1 + max(lp[u], s3) + a[u]);
          else
            dp[v] = max(dp[u], s1 + max(lp[u], s2) + a[u]);
          if (d[v] == d1)
            dp[v] = max(dp[v], d2);
          else
            dp[v] = max(dp[v], d1);
        }
        st.push(v);
      }
    ans = max(ans, d[u] + dp[u]);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i < n; i++) {
    int x, y;
    cin >> x >> y;
    e[x].push_back(y);
    e[y].push_back(x);
  }
  dfs1();
  dfs2();
  cout << ans;
}
