#include <bits/stdc++.h>
using namespace std;
const int nax = 1e5 + 5;
vector<int> g[nax];
long long a[nax], dp[nax], dp_leaf[nax], ans = 0;
array<array<long long, 2>, 3> dp_path[nax];
template <typename T>
void max_self(T& x, T y) {
  x = max(x, y);
}
void dfs_down(int u, int p) {
  dp_leaf[u] = a[u];
  long long m1 = 0, m2 = 0, m3 = 0;
  int v1 = -1, v2 = -1, v3 = -1;
  for (int v : g[u]) {
    if (v != p) {
      dfs_down(v, u);
      max_self(dp_leaf[u], dp_leaf[v] + a[u]);
      max_self(dp[u], dp[v]);
      if (dp_leaf[v] >= m1) {
        m3 = m2;
        v3 = v2;
        m2 = m1;
        v2 = v1;
        m1 = dp_leaf[v];
        v1 = v;
      } else if (dp_leaf[v] >= m2) {
        m3 = m2;
        v3 = v2;
        m2 = dp_leaf[v];
        v2 = v;
      } else if (dp_leaf[v] >= m3) {
        m3 = dp_leaf[v];
        v3 = v;
      }
    }
  }
  max_self(dp[u], a[u] + m1 + m2);
  dp_path[u][0] = {m1 + a[u], v1};
  dp_path[u][1] = {m2 + a[u], v2};
  dp_path[u][2] = {m3 + a[u], v3};
}
void dfs_up(int u, int p) {
  long long up = dp_path[p][0][1] == u ? dp_path[p][1][0] : dp_path[p][0][0];
  for (int v : g[u]) {
    if (v != p) {
      long long his = dp[v];
      long long mine =
          v == dp_path[u][0][1]
              ? dp_path[u][1][0] + max(up, dp_path[u][2][0] - a[u])
          : v == dp_path[u][1][1]
              ? dp_path[u][0][0] + max(up, dp_path[u][2][0] - a[u])
              : dp_path[u][0][0] + max(up, dp_path[u][1][0] - a[u]);
      max_self(ans, his + mine);
    }
  }
  max_self(ans, dp[u]);
  long long m1 = 0, m2 = 0;
  for (int v : g[u]) {
    if (v != p) {
      if (dp[v] >= m1) {
        m2 = m1;
        m1 = dp[v];
      } else if (dp[v] >= m2) {
        m2 = dp[v];
      }
    }
  }
  max_self(ans, m1 + m2);
  if (up + a[u] >= dp_path[u][0][0]) {
    dp_path[u][2] = dp_path[u][1];
    dp_path[u][1] = dp_path[u][0];
    dp_path[u][0] = {up + a[u], p};
  } else if (up + a[u] >= dp_path[u][1][0]) {
    dp_path[u][2] = dp_path[u][1];
    dp_path[u][1] = {up + a[u], p};
  } else if (up + a[u] >= dp_path[u][2][0]) {
    dp_path[u][2] = {up + a[u], p};
  }
  for (int v : g[u]) {
    if (v != p) {
      dfs_up(v, u);
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= int(n); i++) {
    cin >> a[i];
  }
  for (int i = 0; i < int(n - 1); i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  for (int i = 0; i < int(3); i++) dp_path[0][i] = array<long long, 2>();
  dfs_down(1, 0);
  dfs_up(1, 0);
  cout << ans << "\n";
}
