#include <bits/stdc++.h>
using namespace std;
template <typename T>
void chmin(T &x, const T &y) {
  if (x > y) x = y;
}
template <typename T>
void chmax(T &x, const T &y) {
  if (x < y) x = y;
}
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - 48;
    ch = getchar();
  }
  return x * f;
}
const long long N = 1e5 + 10;
long long n, cnt, head[N], dp[N][6], ans = 0x3f3f3f3f, val[N];
struct node {
  long long to, next;
} edge[N << 1];
inline void add(long long u, long long v) {
  edge[++cnt] = {v, head[u]};
  head[u] = cnt;
}
inline void dfs(long long u, long long fa) {
  dp[u][4] = dp[u][2] = dp[u][1] = dp[u][0] = val[u];
  dp[u][3] = 0;
  ;
  for (long long i = head[u]; i; i = edge[i].next) {
    long long v = edge[i].to;
    if (v == fa) continue;
    dfs(v, u);
    chmax(dp[u][0], dp[v][0]);
    chmax(dp[u][0], dp[v][1] + dp[u][1]);
    chmax(dp[u][0], dp[u][2] + dp[v][4]);
    chmax(dp[u][0], dp[u][4] + dp[v][2]);
    chmax(dp[u][1], dp[v][1]);
    chmax(dp[u][1], dp[u][4] + dp[v][4]);
    chmax(dp[u][2], val[u] + dp[v][2]);
    chmax(dp[u][2], dp[u][4] + dp[v][1]);
    chmax(dp[u][2], dp[v][4] + val[u] + dp[u][3]);
    chmax(dp[u][3], dp[v][1]);
    chmax(dp[u][4], dp[v][4] + val[u]);
  }
}
signed main() {
  n = read();
  long long u, v;
  for (long long i = 1; i <= n; i++) val[i] = read();
  for (long long i = 1; i < n; i++) {
    u = read(), v = read();
    add(u, v), add(v, u);
  }
  dfs(1, 0);
  cout << dp[1][0];
  return 0;
  ;
}
