#include <bits/stdc++.h>
const int SIZE = 200005;
int head[SIZE], nex[SIZE], ver[SIZE], Tot;
long long weight[SIZE];
long long DP1[SIZE];
long long DP2[SIZE];
long long DP3[SIZE];
long long Long[SIZE];
void Link(int u, int v) {
  nex[++Tot] = head[u];
  head[u] = Tot;
  ver[Tot] = v;
  nex[++Tot] = head[v];
  head[v] = Tot;
  ver[Tot] = u;
}
inline long long m2(long long A, long long B) { return A > B ? A : B; }
inline long long m3(long long A, long long B, long long C) {
  return m2(A, B) > C ? m2(A, B) : C;
}
inline long long m4(long long A, long long B, long long C, long long D) {
  return m3(A, B, C) > D ? m3(A, B, C) : D;
}
inline long long m5(long long A, long long B, long long C, long long D,
                    long long E) {
  return m4(A, B, C, D) > E ? m4(A, B, C, D) : E;
}
void DFS(int u, int F) {
  Long[u] = weight[u];
  DP1[u] = weight[u];
  long long o = 0;
  for (int i = head[u]; i; i = nex[i]) {
    int v = ver[i];
    if (v == F) continue;
    DFS(v, u);
    long long Tem1 = DP1[u], Tem3 = DP3[u];
    DP1[u] = m3(DP1[u], DP1[v], Long[u] + Long[v]);
    DP2[u] =
        m5(DP2[u], DP2[v], Long[u] + DP3[v], Long[v] + Tem3, Tem1 + DP1[v]);
    DP3[u] = m4(DP3[u], DP3[v] + weight[u], o + (weight[u] + Long[v]),
                Long[u] + DP1[v]);
    Long[u] = m2(Long[u], Long[v] + weight[u]);
    o = m2(o, DP1[v]);
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  int n, u, v;
  std::cin >> n;
  for (int i = 1; i <= n; i++) std::cin >> weight[i];
  for (int i = 1; i < n; i++) {
    std::cin >> u >> v;
    Link(u, v);
  }
  DFS(1, 0);
  std::cout << DP2[1];
  return 0;
}
