#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
using namespace std;
template <class T>
using vec = std::vector<T>;
template <class T>
using vec2d = std::vector<std::vector<T>>;
bool __hack = std::ios::sync_with_stdio(false);
auto __hack1 = cin.tie(nullptr);
struct Input {
  Input(istream &in) : in(&in) {}
  template <class T>
  T next() const {
    T x;
    *in >> x;
    return x;
  }
  int ni() const { return next<int>(); }
  template <class T>
  vec<T> nVec(int n) const {
    vec<T> v(n);
    for (int i = 0; i < n; ++i) {
      v[i] = next<T>();
    }
    return v;
  }
  vec<int64_t> nvi64(int n) const { return nVec<int64_t>(n); }
  istream *in;
};
Input in(cin);
class Output {
 private:
  ostream *out;
  template <typename T>
  void printSingle(const T &value) {
    *out << value;
  }

 public:
  Output(ostream &out) : out(&out) {}
  inline void print() {}
  template <typename T, typename... Ts>
  inline void print(const T &f, const Ts &...args) {
    printSingle(f);
    if (sizeof...(args) != 0) {
      *out << ' ';
      print(args...);
    }
  }
  template <typename... Ts>
  inline void println(const Ts &...args) {
    print(args...);
    *out << '\n';
  }
  template <typename... Ts>
  inline void operator()(const Ts &...args) {
    println(args...);
  }
};
Output out(cout);
namespace template_util {
constexpr int bytecount(uint64_t x) { return x ? 1 + bytecount(x >> 8) : 0; }
template <int N>
struct bytetype {};
template <uint64_t N>
struct minimal_uint : bytetype<bytecount(N)> {};
}  // namespace template_util
void solve(istream &inStream, ostream &outStream) {
  in = Input(inStream);
  out = Output(outStream);
  auto n = in.ni();
  auto a = in.nvi64(n);
  vec2d<int> g(n);
  for (int i = 0; i < (n - 1); ++i) {
    auto x = in.ni() - 1;
    auto y = in.ni() - 1;
    g[y].push_back(x);
    g[x].push_back(y);
  }
  vec<int64_t> bestPathGoesUp(n, 0);
  vec<int64_t> bestBothEndPath(n, 0);
  vec<int64_t> bestPathWithSecond(n, 0);
  int64_t result = 0;
  function<void(int, int)> dfs = [&](int v, int p) {
    vec<int> children;
    for (auto to : g[v]) {
      if (to != p) {
        children.push_back(to);
        dfs(to, v);
      }
    }
    bestPathGoesUp[v] = a[v];
    bestBothEndPath[v] = a[v];
    vec<pair<int64_t, int>> vals;
    vec<pair<int64_t, int>> vals2;
    for (auto u : children) {
      bestPathGoesUp[v] = max(bestPathGoesUp[v], bestPathGoesUp[u] + a[v]);
      bestBothEndPath[v] = max(bestBothEndPath[v], bestBothEndPath[u]);
      bestPathWithSecond[v] =
          max(bestPathWithSecond[v], bestPathWithSecond[u] + a[v]);
      vals.push_back({bestPathGoesUp[u], u});
      vals2.push_back({bestBothEndPath[u], u});
    }
    sort(vals.begin(), vals.end());
    sort(vals2.begin(), vals2.end());
    if (vals.size() >= 2) {
      bestBothEndPath[v] =
          max(bestBothEndPath[v],
              vals.end()[-1].first + vals.end()[-2].first + a[v]);
    }
    bestBothEndPath[v] = max(bestBothEndPath[v], bestPathGoesUp[v]);
    result = max(result, bestBothEndPath[v]);
    result = max(result, bestPathWithSecond[v]);
    if (vals2.size() >= 2) {
      result = max(result, vals2.end()[-1].first + vals2.end()[-2].first);
    }
    for (int i = (int)vals2.size() - 1, j = 0; i >= 0; ++j, --i) {
      int64_t cur = vals2[i].first + a[v];
      result = max(result, cur);
      bestPathWithSecond[v] = max(bestPathWithSecond[v], cur);
      for (int k = (int)vals.size() - 1, j2 = 0; k >= 0 && j2 < 2; --k) {
        if (vals2[i].second != vals[k].second) {
          cur += vals[k].first;
          if (j2 == 0) {
            bestPathWithSecond[v] = max(bestPathWithSecond[v], cur);
          }
          result = max(result, cur);
          ++j2;
        }
      }
      result = max(result, cur);
    }
    vals2.clear();
    for (auto u : children) {
      vals2.push_back({bestPathWithSecond[u], u});
    }
    sort(vals2.begin(), vals2.end());
    for (int i = (int)vals2.size() - 1, j = 0; i >= 0; ++j, --i) {
      int64_t cur = vals2[i].first + a[v];
      result = max(result, cur);
      for (int k = (int)vals.size() - 1; k >= 0; --k) {
        if (vals2[i].second != vals[k].second) {
          result = max(result, cur + vals[k].first);
          break;
        }
      }
    }
  };
  dfs(0, -1);
  out(result);
}
int main() {
  solve(cin, cout);
  return 0;
}
