#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100100;
const int INF = 0x3f3f3f3f;
int n;
vector<int> G[MAXN];
int w[MAXN];
long long f[MAXN][2], g[MAXN], h[MAXN], down[MAXN];
void dfs(int cur, int fa) {
  f[cur][0] = w[cur];
  f[cur][1] = w[cur];
  g[cur] = w[cur];
  h[cur] = 0;
  down[cur] = w[cur];
  for (int i = 0; i < G[cur].size(); i++) {
    int u = G[cur][i];
    if (u == fa) continue;
    dfs(u, cur);
    f[cur][0] = max(f[cur][0], f[u][0]);
    f[cur][0] = max(f[cur][0], f[cur][1] + f[u][1]);
    f[cur][0] = max(f[cur][0], down[cur] + g[u]);
    f[cur][0] = max(f[cur][0], g[cur] + down[u]);
    f[cur][1] = max(f[cur][1], f[u][1]);
    f[cur][1] = max(f[cur][1], down[cur] + down[u]);
    g[cur] = max(g[cur], w[cur] + g[u]);
    g[cur] = max(g[cur], down[cur] + f[u][1]);
    g[cur] = max(g[cur], down[u] + w[cur] + h[cur]);
    h[cur] = max(h[cur], f[u][1]);
    down[cur] = max(down[cur], down[u] + w[cur]);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &w[i]);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    G[u].push_back(v);
    G[v].push_back(u);
  }
  dfs(1, 0);
  printf("%I64d", f[1][0]);
  return 0;
}
