#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010

vector<int> way[SIZE];
int point[SIZE];
int ans = -INF;

pair<pair<int,int>,int> dfs(int now, int back = -1){
  vector<int> vec, vec2;
  int sum = 0;
  
  for(int i=0;i<way[now].size();i++){
    if(way[now][i] == back) continue;
    auto p = dfs(way[now][i], now);
    vec.push_back(p.first.first - p.first.second);
    vec2.push_back(p.second - p.first.second);
    sum += p.first.second;
  }

  vec.push_back(0);
  vec.push_back(0);
  vec2.push_back(0);
  sort(vec.begin(), vec.end(), greater<int>());
  sort(vec2.begin(), vec2.end(), greater<int>());

  ans = max(ans, sum + vec[0] + vec[1] + point[now]);
  ans = max(ans, sum + vec2[0] + point[now]);
  
  return {{max(0, sum + vec[0] + point[now] - 1), max(0, sum + point[now] - 2)},
      max({0, sum + vec[0] + vec[1] + point[now] - 2, sum + vec2[0] + point[now] - 2})};
}

int main(){
  int n;

  scanf("%d", &n);
  
  for(int i=0;i<n;i++){
    scanf("%d", point+i);
  }

  for(int i=0;i<n-1;i++){
    int a, b;
    scanf("%d%d", &a, &b);
    a--; b--;
    way[a].push_back(b);
    way[b].push_back(a);
  }

  dfs(0);

  printf("%d\n", ans);
  
  return 0;
}

