#include <bits/stdc++.h>
using namespace std;
long long int n, A[100005], x, y, ans;
vector<int> v[100005];
unordered_map<long long int, bool> mark[100005];
unordered_map<long long int, long long int> dp[100005], dp2[100005];
long long int dfs(long long int x, long long int back) {
  if (mark[x][back] != false) return dp[x][back];
  long long int d1 = A[x], d2 = A[x], mx1 = -1, mx2 = -1;
  for (auto i : v[x]) {
    if (i == back) continue;
    dfs(i, x);
    d1 = max(d1, dp[i][x]);
    d2 = max(d2, dp2[i][x] + A[x]);
    mx1 = max(mx1, dp2[i][x]);
    if (mx1 > mx2) swap(mx1, mx2);
  }
  mark[x][back] = true;
  dp2[x][back] = d2;
  dp[x][back] = max(d1, max(mx1, 0ll) + mx2 + A[x]);
  return dp[x][back];
}
int main() {
  scanf("%lld", &n);
  for (int i = 1; i <= n; i++) scanf("%lld", &A[i]);
  for (int i = 1; i < n; i++) {
    scanf("%lld %lld", &x, &y);
    v[x].push_back(y);
    v[y].push_back(x);
  }
  for (int i = 1; i <= n; i++) {
    for (auto j : v[i]) {
      ans = max(ans, dfs(i, j) + dfs(j, i));
    }
  }
  printf("%lld", ans);
  return 0;
}
