#include <bits/stdc++.h>
using namespace std;
const int MaxN = 100005;
int n;
vector<int> adj[MaxN];
int Pd[MaxN];
long long a[MaxN];
long long f[MaxN], f1[MaxN], f2[MaxN], f3[MaxN];
long long g[MaxN], g1[MaxN], h1[MaxN], h2[MaxN];
void DFS1(int u) {
  f[u] = f1[u] = f2[u] = f3[u] = 0;
  for (auto v : adj[u]) {
    if (Pd[u] != v) {
      Pd[v] = u;
      DFS1(v);
      f[u] = max(f[u], f[v]);
      if (f[v] >= h1[u]) {
        h2[u] = h1[u];
        h1[u] = f[v];
      } else {
        h2[u] = max(h2[u], f[v]);
      }
      if (f1[v] >= f1[u]) {
        f3[u] = f2[u];
        f2[u] = f1[u];
        f1[u] = f1[v];
      } else if (f1[v] >= f2[u]) {
        f3[u] = f2[u];
        f2[u] = f1[v];
      } else if (f1[v] > f3[u]) {
        f3[u] = f1[v];
      }
    }
  }
  f[u] = max(f[u], f1[u] + f2[u] + a[u]);
  f1[u] += a[u];
  f2[u] += a[u];
  f3[u] += a[u];
}
void DFS2(int u) {
  if (Pd[u] != 0) {
    int w = Pd[u];
    g[u] = g[w];
    g[u] = max(g[u], g1[w]);
    g[u] = max(g[u], (f[u] == h1[w] ? h2[w] : h1[w]));
    g[u] = max(g[u], (f1[w] == f1[u] + a[w] ? f2[w] : f1[w]));
    g[u] = max(g[u], g1[w] + (f1[w] == f1[u] + a[w] ? f2[w] : f1[w]) - a[w]);
    if (f1[w] == f1[u] + a[w]) {
      g[u] = max(g[u], f2[w] + f3[w] - a[w]);
    } else if (f2[w] == f1[u] + a[w]) {
      g[u] = max(g[u], f1[w] + f3[w] - a[w]);
    } else {
      g[u] = max(g[u], f1[w] + f2[w] - a[w]);
    }
    g1[u] = g1[w] + a[u];
    g1[u] = max(g1[u], (f1[w] == f1[u] + a[w] ? f2[w] : f1[w]) + a[u]);
  }
  for (auto v : adj[u]) {
    if (Pd[v] == u) {
      DFS2(v);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  int u, v;
  for (int i = 1; i < n; i++) {
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  DFS1(1);
  DFS2(1);
  long long Res = 0;
  for (int i = 1; i <= n; i++) {
    Res = max(Res, f[i] + g[i]);
  }
  cout << Res;
  return 0;
}
