#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int n;
long long f[N][2], down[N], g[N], h[N], a[N];
vector<int> e[N];
template <typename T>
inline void chkmax(T &x, T y) {
  x = max(x, y);
}
template <typename T>
inline void chkmin(T &x, T y) {
  x = min(x, y);
}
template <typename T>
inline void read(T &x) {
  T f = 1;
  x = 0;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -f;
  for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0';
  x *= f;
}
inline void DFS(int u, int par) {
  f[u][0] = f[u][1] = down[u] = g[u] = a[u];
  for (unsigned i = 0; i < e[u].size(); ++i) {
    int v = e[u][i];
    if (v == par) continue;
    DFS(v, u);
    chkmax(f[u][0], f[v][0]);
    chkmax(f[u][0], f[u][1] + f[v][1]);
    chkmax(f[u][0], down[u] + g[v]);
    chkmax(f[u][0], down[v] + g[u]);
    chkmax(f[u][1], f[v][1]);
    chkmax(f[u][1], down[u] + down[v]);
    chkmax(g[u], g[v] + a[u]);
    chkmax(g[u], down[u] + f[v][1]);
    chkmax(g[u], down[v] + a[u] + h[u]);
    chkmax(h[u], f[v][1]);
    chkmax(down[u], a[u] + down[v]);
  }
}
int main() {
  read(n);
  for (int i = 1; i <= n; ++i) read(a[i]);
  for (int i = 1; i < n; ++i) {
    int u, v;
    read(u);
    read(v);
    e[u].push_back(v);
    e[v].push_back(u);
  }
  DFS(1, 0);
  printf("%lld\n", f[1][0]);
  return 0;
}
