#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <class T>
inline bool Min(T &a, T b) {
  return a > b ? (a = b, true) : false;
}
template <class T>
inline bool Max(T &a, T b) {
  return a < b ? (a = b, true) : false;
}
inline int ni() {
  int a;
  scanf("%d", &a);
  return a;
}
inline ll nl() {
  ll a;
  scanf("%lld", &a);
  return a;
}
inline double nd() {
  double a;
  scanf("%lf", &a);
  return a;
}
inline void pi(int a) { printf("%d ", a); }
inline void pl(ll a) { printf("%lld ", a); }
inline void pd(double a) { printf("%.12lf ", a); }
const int N = 1e5 + 100;
vector<int> gp[N];
ll a[N];
ll ans = 0;
ll down1[N];
ll down2[N];
ll path[N];
void dfs(int v, int p) {
  down1[v] = a[v];
  path[v] = a[v];
  ll bestpath = 0;
  for (int next : gp[v])
    if (next != p) {
      dfs(next, v);
      Max(ans, path[v] + path[next]);
      Max(ans, down1[v] + down2[next]);
      Max(ans, down2[v] + down1[next]);
      Max(down2[v], down2[next] + a[v]);
      Max(down2[v], path[next] + down1[v]);
      Max(down2[v], bestpath + down1[next] + a[v]);
      Max(path[v], path[next]);
      Max(path[v], down1[v] + down1[next]);
      Max(bestpath, path[next]);
      Max(down1[v], down1[next] + a[v]);
    }
}
void solve() {
  int n = ni();
  for (int i = 0; i < n; i++) a[i] = ni();
  for (int i = 0; i < n - 1; i++) {
    int a = ni() - 1;
    int b = ni() - 1;
    gp[a].push_back(b);
    gp[b].push_back(a);
  }
  dfs(0, -1);
  pl(ans);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  srand((int)clock());
  solve();
  return 0;
}
