#include <bits/stdc++.h>
using namespace std;
template <class T>
bool ckmin(T &a, const T &b) {
  return (a > b ? a = b, 1 : 0);
}
template <class T>
bool ckmax(T &a, const T &b) {
  return (a < b ? a = b, 1 : 0);
}
template <class T>
void read(T &x) {
  cin >> x;
}
template <class T, class... U>
void read(T &x, U &...y) {
  read(x);
  read(y...);
}
template <class T>
void write(const T &x) {
  cout << x;
}
template <class T, class... U>
void write(const T &x, const U &...y) {
  write(x);
  write(y...);
}
template <class T>
void print(const T &x) {
  write(x, "\n");
}
template <class T, class... U>
void print(const T &x, const U &...y) {
  write(x, " ");
  print(y...);
}
template <class T>
void DBG(const T &t) {
  write(t, "]", '\n');
  cout.flush();
}
template <class T, class... U>
void DBG(const T &t, const U &...u) {
  write(t, ", ");
  DBG(u...);
}
const int MOD = 1000000007;
const int INF = 1000000000;
const int N = 100005;
int n, a[N];
vector<int> adj[N];
long long dp[N][5];
void search(int x, int p) {
  dp[x][0] = dp[x][1] = dp[x][2] = dp[x][4] = a[x];
  dp[x][3] = 0;
  for (auto &y : adj[x])
    if (y != p) {
      search(y, x);
      ckmax(dp[x][0], dp[y][0]);
      ckmax(dp[x][0], dp[y][1] + dp[x][1]);
      ckmax(dp[x][0], dp[x][2] + dp[y][4]);
      ckmax(dp[x][0], dp[x][4] + dp[y][2]);
      ckmax(dp[x][1], dp[y][1]);
      ckmax(dp[x][1], dp[x][4] + dp[y][4]);
      ckmax(dp[x][2], a[x] + dp[y][2]);
      ckmax(dp[x][2], dp[x][4] + dp[y][1]);
      ckmax(dp[x][2], dp[y][4] + a[x] + dp[x][3]);
      ckmax(dp[x][3], dp[y][1]);
      ckmax(dp[x][4], dp[y][4] + a[x]);
    }
}
int main() {
  cin.tie(0)->sync_with_stdio(0);
  read(n);
  for (int i = (1); i <= (n); ++i) read(a[i]);
  for (int i = 1, x, y; i < n; ++i) {
    read(x, y);
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  memset(dp, 0, sizeof(dp));
  search(1, 0);
  print(dp[1][0]);
}
