#include <bits/stdc++.h>
using namespace std;
int Go[100005 << 1], Next[100005 << 1], End[100005], father[100005], cnt;
long long f[100005][3][3], big1, big2, big3, big4, ans;
int a[100005], n, x, y, i, id;
void add(int u, int v) {
  Go[++cnt] = v;
  Next[cnt] = End[u];
  End[u] = cnt;
}
inline void Max(long long &x, long long y) {
  if (y > x) x = y;
}
inline void up(long long &x, long long &y, long long z) {
  if (z > x)
    y = x, x = z;
  else if (z > y)
    y = z;
}
void DFS(int x);
long long DP(int x, int p1, int q1, int p2, int q2) {
  big1 = big2 = id = 0;
  for (int i = End[x], y; i; i = Next[i])
    if ((y = Go[i]) != father[x])
      if (f[y][p1][q1] > big1) big1 = f[y][p1][q1], id = y;
  for (int i = End[x], y; i; i = Next[i])
    if ((y = Go[i]) != father[x])
      if (y != id) Max(big2, f[y][p2][q2]);
  long long ret = big1 + big2;
  big1 = big2 = id = 0;
  for (int i = End[x], y; i; i = Next[i])
    if ((y = Go[i]) != father[x])
      if (f[y][p2][q2] > big1) big1 = f[y][p2][q2], id = y;
  for (int i = End[x], y; i; i = Next[i])
    if ((y = Go[i]) != father[x])
      if (y != id) Max(big2, f[y][p1][q1]);
  Max(ret, big1 + big2);
  return ret;
}
long long DP2(int x, int p1, int q1, int p2, int q2) {
  big1 = big2 = big3 = id = 0;
  for (int i = End[x], y; i; i = Next[i])
    if ((y = Go[i]) != father[x])
      if (f[y][p2][q2] > big3) big3 = f[y][p2][q2], id = y;
  for (int i = End[x], y; i; i = Next[i])
    if ((y = Go[i]) != father[x])
      if (y != id) up(big1, big2, f[y][p1][q1]);
  long long ret = big1 + big2 + big3;
  int ch = 0;
  big1 = big2 = big3 = id = 0;
  for (int i = End[x], y; i; i = Next[i])
    if ((y = Go[i]) != father[x])
      if (f[y][p1][q1] > big1) big1 = f[y][p1][q1], ch = y;
  for (int i = End[x], y; i; i = Next[i])
    if ((y = Go[i]) != father[x])
      if (y != ch)
        if (f[y][p2][q2] > big3) big3 = f[y][p2][q2], id = y;
  for (int i = End[x], y; i; i = Next[i])
    if ((y = Go[i]) != father[x])
      if (y != ch && y != id) Max(big2, f[y][p1][q1]);
  Max(ret, big1 + big2 + big3);
  big2 = big3 = id = 0;
  for (int i = End[x], y; i; i = Next[i])
    if ((y = Go[i]) != father[x])
      if (y != ch)
        if (f[y][p1][q1] > big2) big2 = f[y][p1][q1], id = y;
  for (int i = End[x], y; i; i = Next[i])
    if ((y = Go[i]) != father[x])
      if (y != ch && y != id) Max(big3, f[y][p2][q2]);
  Max(ret, big1 + big2 + big3);
  return ret;
}
void DFS(int x) {
  int son = 0;
  for (int i = End[x], y; i; i = Next[i])
    if ((y = Go[i]) != father[x]) father[y] = x, DFS(y), son++;
  for (int i = End[x], y; i; i = Next[i])
    if ((y = Go[i]) != father[x])
      Max(f[x][0][1], f[y][0][1]), Max(f[x][1][0], f[y][1][0]);
  f[x][0][1] += a[x];
  f[x][1][0] += a[x];
  big1 = big2 = big3 = big4 = 0;
  for (int i = End[x], y; i; i = Next[i])
    if ((y = Go[i]) != father[x])
      Max(f[x][0][2], f[y][0][2]), up(big1, big2, f[y][0][1]),
          Max(f[x][2][0], f[y][2][0]), up(big3, big4, f[y][1][0]);
  Max(f[x][0][2], big1 + big2 + a[x]);
  Max(f[x][2][0], big3 + big4 + a[x]);
  for (int i = End[x], y; i; i = Next[i])
    if ((y = Go[i]) != father[x]) Max(f[x][1][2], f[y][1][2] + a[x]);
  Max(f[x][1][2], DP(x, 1, 0, 0, 2) + a[x]);
  for (int i = End[x], y; i; i = Next[i])
    if ((y = Go[i]) != father[x]) Max(f[x][2][1], f[y][2][1] + a[x]);
  Max(f[x][2][1], DP(x, 0, 1, 2, 0) + a[x]);
  for (int i = End[x], y; i; i = Next[i])
    if ((y = Go[i]) != father[x]) Max(f[x][2][2], f[y][2][2]);
  Max(f[x][2][2], DP(x, 2, 0, 0, 2));
  Max(f[x][2][2], DP(x, 2, 1, 0, 1) + a[x]);
  Max(f[x][2][2], DP(x, 1, 2, 1, 0) + a[x]);
  Max(f[x][2][2], DP2(x, 1, 0, 0, 2) + a[x]);
  Max(f[x][2][2], DP2(x, 0, 1, 2, 0) + a[x]);
  for (int u = 0; u < 3; u++)
    for (int v = 0; v < 3; v++)
      for (int A = 0; A < 3; A++)
        for (int B = 0; B < 3; B++)
          if (A < u && B < v) Max(f[x][u][v], f[x][A][B]);
}
int main() {
  scanf("%d", &n);
  long long sum = 0;
  for (i = 1; i <= n; i++) scanf("%d", &a[i]), sum += a[i];
  for (i = 1; i < n; i++) scanf("%d%d", &x, &y), add(x, y), add(y, x);
  DFS(1);
  printf("%I64d\n", f[1][2][2]);
}
