#include <bits/stdc++.h>
using namespace std;
const long long int maxn = (3e5) + 10, mod = 1e9 + 7;
long long int n, a[maxn], dp_D[maxn], dp_U[maxn], pd_D[maxn], pd_U[maxn];
vector<long long int> v[maxn];
void pre_DFS1(long long int x, long long int p) {
  pd_D[x] = a[x];
  for (auto u : v[x]) {
    if (u == p) continue;
    pre_DFS1(u, x);
    pd_D[x] = max(pd_D[x], pd_D[u] + a[x]);
  }
}
void pre_DFS2(long long int x, long long int p) {
  long long int aa = -1, bb = -1;
  for (auto u : v[x]) {
    if (u == p) continue;
    if (pd_D[u] >= aa) {
      swap(aa, bb);
      aa = pd_D[u];
    } else if (pd_D[u] >= bb)
      bb = pd_D[u];
  }
  if (bb == -1) bb++;
  if (aa == -1) aa++;
  for (auto u : v[x]) {
    if (u == p) continue;
    if (aa == pd_D[u])
      pd_U[u] = max(pd_U[x] + a[u], bb + a[u] + a[x]);
    else
      pd_U[u] = max(pd_U[x] + a[u], aa + a[u] + a[x]);
    pre_DFS2(u, x);
  }
}
void DFS1(long long int x, long long int p) {
  dp_D[x] = pd_D[x];
  long long int aa = -1, bb = -1;
  for (auto u : v[x]) {
    if (u == p) continue;
    DFS1(u, x);
    dp_D[x] = max(dp_D[x], dp_D[u]);
    if (pd_D[u] >= aa) {
      swap(aa, bb);
      aa = pd_D[u];
    } else if (pd_D[u] > bb)
      bb = pd_D[u];
  }
  if (bb == -1) bb++;
  if (aa == -1) aa++;
  dp_D[x] = max(dp_D[x], aa + bb + a[x]);
}
void DFS2(long long int x, long long int p) {
  long long int aa = -1, bb = -1, cc = -1, dd = -1;
  for (auto u : v[x]) {
    if (u == p) continue;
    if (pd_D[u] >= aa) {
      swap(bb, cc);
      swap(aa, bb);
      aa = pd_D[u];
    } else if (pd_D[u] >= bb) {
      swap(bb, cc);
      bb = pd_D[u];
    } else if (pd_D[u] >= cc)
      cc = pd_D[u];
  }
  if (aa == -1) aa++;
  if (bb == -1) bb++;
  if (cc == -1) cc++;
  long long int qq = -1, ww = -1;
  for (auto u : v[x]) {
    if (u == p) continue;
    if (pd_D[u] == aa)
      dp_U[u] = max(bb + pd_U[x], bb + cc + a[x]);
    else if (pd_D[u] == bb)
      dp_U[u] = max(aa + pd_U[x], aa + cc + a[x]);
    else
      dp_U[u] = max(aa + pd_U[x], aa + bb + a[x]);
    dp_U[u] = max(dp_U[u], dp_U[x]);
    if (dp_D[u] >= qq) {
      swap(qq, ww);
      qq = dp_D[u];
    } else if (dp_D[u] >= ww)
      ww = dp_D[u];
  }
  for (auto u : v[x]) {
    if (u == p) continue;
    if (dp_D[u] == qq)
      dp_U[u] = max(dp_U[u], ww);
    else
      dp_U[u] = max(dp_U[u], qq);
  }
  for (auto u : v[x]) {
    if (u == p) continue;
    DFS2(u, x);
  }
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  for (long long int i = 1; i <= n; i++) cin >> a[i];
  for (long long int i = 0; i < n - 1; i++) {
    long long int x, y;
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  pre_DFS1(1, -1);
  pre_DFS2(1, -1);
  DFS1(1, -1);
  DFS2(1, -1);
  long long int ans = 0;
  for (long long int i = 1; i <= n; i++) {
    ans = max(ans, dp_D[i] + dp_U[i]);
  }
  cout << ans << endl;
  return 0;
}
