#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
vector<int> G[maxn];
long long dp[maxn][4];
int f[maxn], a[maxn];
void dfs(int x) {
  long long p0 = 0, p1 = 0, p2 = 0, p3 = 0, p00 = 0, p10 = 0;
  for (int i = 0; i < G[x].size(); i++)
    if (G[x][i] != f[x]) {
      int u = G[x][i];
      f[u] = x;
      dfs(u);
      dp[x][1] = max(dp[x][1], dp[u][0] + p0 + a[x]);
      dp[x][2] = max(dp[x][2], max(dp[u][0] + p1, dp[u][1] + p0) + a[x]);
      dp[x][3] = max(dp[x][3], max(dp[u][2] + p0, dp[u][0] + p2) + a[x]);
      dp[x][3] = max(dp[x][3], dp[u][1] + p1);
      dp[x][3] = max(dp[x][3], max(dp[u][1] + p00, dp[u][0] + p10) + a[x]);
      p00 = max(p00, dp[u][0] + p0);
      p10 = max(p10, max(dp[u][1] + p0, dp[u][0] + p1));
      p0 = max(dp[u][0], p0);
      p1 = max(dp[u][1], p1);
      p2 = max(dp[u][2], p2);
      p3 = max(dp[u][3], p3);
    }
  dp[x][0] = max(dp[x][0], p0 + a[x]);
  dp[x][1] = max(dp[x][1], max((long long)a[x], p1));
  dp[x][2] = max(dp[x][2], max(p2, p1) + a[x]);
  dp[x][3] = max(p0 + a[x], max(dp[x][3], max(p3, p1 + a[x])));
}
int main() {
  int n, u, v;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 0; i < n - 1; i++) {
    scanf("%d%d", &u, &v);
    G[u].push_back(v);
    G[v].push_back(u);
  }
  dfs(1);
  cout << dp[1][3] << endl;
  return 0;
}
