#include <bits/stdc++.h>
using namespace std;
vector<int> v[((int)(1e5 + 1))];
long long int val[((int)(1e5 + 1))], dis[((int)(1e5 + 1))],
    tr[((int)(1e5 + 1)) * 4], carry[((int)(1e5 + 1)) * 4];
int go[((int)(1e5 + 1))];
bool vis[((int)(1e5 + 1))];
void update(int n, int b, int e, int i, int j, long long int v) {
  if (j < b || e < i) return;
  if (i <= b && j >= e) {
    carry[n] += v;
    tr[n] += v;
    return;
  }
  int l, r, m;
  m = (b + e) >> 1;
  l = n << 1;
  r = l + 1;
  update(l, b, m, i, j, v);
  update(r, m + 1, e, i, j, v);
  tr[n] = max(tr[l], tr[r]) + carry[n];
}
long long int get(int n, int b, int e, int i, int j, long long int car) {
  if (j < b || e < i) return 0;
  if (i <= b && j >= e) return tr[n] + car;
  int l, r, m;
  m = (b + e) >> 1;
  l = n << 1;
  r = l + 1;
  car += carry[n];
  return max(get(l, b, m, i, j, car), get(r, m + 1, e, i, j, car));
}
pair<int, long long int> diamtr(int n, int p) {
  dis[n] = dis[p] + val[n];
  pair<int, long long int> ans, tmp;
  ans.second = dis[n];
  ans.first = n;
  go[n] = n;
  for (int i = 0; i < v[n].size(); i++) {
    if (v[n][i] != p && !vis[v[n][i]]) {
      tmp = diamtr(v[n][i], n);
      if (tmp.second > ans.second) {
        ans = tmp;
        go[n] = v[n][i];
      }
    }
  }
  return ans;
}
long long int visit(int n, int p) {
  if (go[n] == n) return 0;
  long long int ans = visit(go[n], n);
  vis[n] = 1;
  for (int i = 0; i < v[n].size(); i++) {
    if (v[n][i] != p && v[n][i] != go[n]) {
      ans = max(ans, diamtr(diamtr(v[n][i], 0).first, 0).second);
    }
  }
  return ans;
}
long long int getdis(int n, int p) {
  long long int ans = 0;
  for (int i = 0; i < v[n].size(); i++) {
    if (v[n][i] != p) ans = max(ans, getdis(v[n][i], n));
  }
  return ans + val[n];
}
long long int cntdis(int n) {
  long long int ans = 0;
  for (int i = 0; i < v[n].size(); i++) {
    if (v[n][i] != go[n] && n != go[v[n][i]])
      ans = max(ans, getdis(v[n][i], n));
  }
  return ans;
}
int main() {
  int n, i, a, b, tot;
  long long int ans, tmp, da, db;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%lld", &val[i]);
  }
  for (i = 1; i < n; i++) {
    scanf("%d %d", &a, &b);
    v[b].push_back(a);
    v[a].push_back(b);
  }
  i = diamtr(1, 0).first;
  memset(go, 0, sizeof go);
  ans = diamtr(i, 0).second;
  tmp = 0;
  a = i;
  b = go[a];
  da = cntdis(a);
  db = cntdis(b);
  tmp = max(tmp, da + db);
  update(1, 1, n, 1, 1, da);
  tot = 1;
  while (b != go[b]) {
    update(1, 1, n, 1, tot, -val[b]);
    tot++;
    a = b;
    b = go[b];
    update(1, 1, n, tot, tot, db);
    db = cntdis(b);
    tmp = max(tmp, db + get(1, 1, n, 1, tot, 0));
  }
  tmp = max(tmp, visit(i, 0));
  printf("%lld\n", ans + tmp);
  return 0;
}
