#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
vector<int> E;
vector<int> a[N];
int value[N];
long long down[N];
long long max_path[N];
int n;
long long calc_down(int edge_index) {
  long long &ans = down[edge_index];
  if (ans != -1) return ans;
  int v = E[edge_index];
  ans = value[v];
  for (int e : a[v])
    if (e != (edge_index ^ 1)) ans = max(ans, calc_down(e) + value[v]);
  return ans;
}
long long calc_max_path(int edge_index) {
  long long &ans = max_path[edge_index];
  if (ans != -1) return ans;
  int v = E[edge_index];
  long long first = 0, second = 0;
  for (int e : a[v])
    if (e != (edge_index ^ 1)) {
      long long cur = calc_down(e);
      if (first <= cur)
        second = first, first = cur;
      else if (second < cur)
        second = cur;
      ans = max(ans, calc_max_path(e));
    }
  return ans = max(ans, first + second + value[v]);
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> value[i];
  for (int i = 1; i < n; ++i) {
    int u, v;
    cin >> u >> v;
    a[u].push_back(E.size());
    E.push_back(v);
    a[v].push_back(E.size());
    E.push_back(u);
  }
  memset(down, -1, sizeof down);
  memset(max_path, -1, sizeof max_path);
  long long ans = 0;
  for (int i = 0; i < E.size(); i += 2)
    ans = max(ans, calc_max_path(i) + calc_max_path(i ^ 1));
  cout << ans << endl;
}
