#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
long long dp[maxn][3], a[maxn], to_leaf[maxn];
long long ext[maxn];
vector<int> g[maxn];
void dfs(int u, int fa) {
  dp[u][1] = dp[u][2] = a[u];
  to_leaf[u] = a[u];
  ext[u] = a[u];
  long long pref = 0;
  for (int i = 0; i < (int)g[u].size(); i++) {
    int v = g[u][i];
    if (v == fa) continue;
    dfs(v, u);
    dp[u][2] = max(dp[u][2], dp[v][2]);
    dp[u][2] = max(dp[u][2], dp[v][1] + dp[u][1]);
    dp[u][2] = max(dp[u][2], ext[v] + to_leaf[u]);
    dp[u][2] = max(dp[u][2], ext[u] + to_leaf[v]);
    dp[u][1] = max(dp[u][1], to_leaf[u] + to_leaf[v]);
    dp[u][1] = max(dp[u][1], dp[v][1]);
    ext[u] = max(ext[u], ext[v] + a[u]);
    ext[u] = max(ext[u], to_leaf[u] + dp[v][1]);
    ext[u] = max(ext[u], pref + to_leaf[v] + a[u]);
    pref = max(pref, dp[v][1]);
    to_leaf[u] = max(to_leaf[u], to_leaf[v] + a[u]);
  }
}
int main() {
  int n, u, v;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%lld", a + i);
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &u, &v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(1, -1);
  printf("%lld\n", dp[1][2]);
  return 0;
}
