#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100002;
long long f1[MAXN], f2[MAXN];
vector<int> e[MAXN];
long long a[MAXN];
long long ans = 0;
void dfs1(int v, int p) {
  long long b = 0, c = 0, d = 0;
  for (int i = 0; i < e[v].size(); i++) {
    int u = e[v][i];
    if (u == p) continue;
    dfs1(u, v);
    if (f1[u] > c) c = f1[u];
    if (c > b) swap(b, c);
    if (f2[u] > d) d = f2[u];
  }
  f1[v] = b + a[v];
  f2[v] = max(b + c + a[v], d);
}
void dfs2(int v, int p, long long c1, long long c2) {
  ans = max(ans, c2 + f2[v]);
  long long b = c1, c = 0, d = 0, ee = c2, f = -1000 * 100;
  for (int i = 0; i < e[v].size(); i++) {
    int u = e[v][i];
    if (u == p) continue;
    if (f1[u] > d) d = f1[u];
    if (d > c) swap(d, c);
    if (c > b) swap(c, b);
    if (f2[u] > f) f = f2[u];
    if (f > ee) swap(ee, f);
  }
  for (int i = 0; i < e[v].size(); i++) {
    long long n1, n2;
    int u = e[v][i];
    if (u == p) continue;
    if (f2[u] == ee)
      n2 = f;
    else
      n2 = ee;
    if (f1[u] == b)
      n1 = c + a[v], n2 = max(n2, c + d + a[v]);
    else if (f1[u] == c)
      n1 = b + a[v], n2 = max(n2, b + d + a[v]);
    else
      n1 = b + a[v], n2 = max(n2, b + c + a[v]);
    dfs2(u, v, n1, n2);
  }
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    e[u].push_back(v);
    e[v].push_back(u);
  }
  dfs1(1, 1);
  dfs2(1, 1, 0, -n);
  cout << ans << endl;
  return 0;
}
