#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
const long long INF = 0x3f3f3f3f3f3f3f3f;
template <typename T>
inline void read(T &AKNOI) {
  T x = 0, flag = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') flag = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  AKNOI = flag * x;
}
template <typename T>
inline void cmax(T &x, T y) {
  if (x < y) x = y;
}
int n, a[MAXN];
long long dp[MAXN][4], tmp[MAXN];
vector<int> e[MAXN];
void DFS(int u, int fa) {
  dp[u][0] = dp[u][1] = dp[u][2] = dp[u][3] = a[u];
  for (auto v : e[u]) {
    if (v == fa) continue;
    DFS(v, u);
    cmax(dp[u][0], dp[v][0]);
    cmax(dp[u][0], dp[u][2] + dp[v][2]);
    cmax(dp[u][0], dp[u][3] + dp[v][1]);
    cmax(dp[u][0], dp[u][1] + dp[v][3]);
    cmax(dp[u][1], dp[v][1] + a[u]);
    cmax(dp[u][1], dp[u][3] + dp[v][2]);
    cmax(dp[u][1], tmp[u] + a[u] + dp[v][3]);
    cmax(dp[u][2], dp[u][3] + dp[v][3]);
    cmax(dp[u][2], dp[v][2]);
    cmax(dp[u][3], dp[v][3] + a[u]);
    cmax(tmp[u], dp[v][2]);
  }
}
void init() {
  read(n);
  for (int i = 1; i <= n; ++i) {
    read(a[i]);
  }
  for (int i = 1, u, v; i < n; ++i) {
    read(u);
    read(v);
    e[u].push_back(v);
    e[v].push_back(u);
  }
}
void solve() {
  DFS(1, 0);
  printf("%lld\n", dp[1][0]);
}
int main() {
  init();
  solve();
  return 0;
}
