#include<bits/stdc++.h>
using namespace std;
using Int = long long;

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<Int> c(n);
  for(Int i=0;i<n;i++) cin>>c[i];
  
  vector<vector<Int> > G(n);
  for(Int i=1;i<n;i++){
    Int x,y;
    cin>>x>>y;
    x--;y--;
    G[x].emplace_back(y);
    G[y].emplace_back(x);
  }
  
  const Int INF = 1e9;
  Int ans=-INF;
  vector<Int> dp1(n,-INF),dp2(n,-INF),dp3(n,-INF);
  
  function<void(Int, Int)> dfs=
    [&](Int v,Int p){
      for(Int u:G[v]) if(u!=p) dfs(u,v);
      
      Int res=0;
      vector<Int> w;
      for(Int u:G[v]){
	if(u==p) continue;
	res+=max(0LL,dp2[u]-2);
	w.emplace_back((dp1[u]-1)-max(0LL,dp2[u]-2));	
      }
	
      for(Int u:G[v]){
	if(u==p) continue;
	chmax(dp1[v],c[v]+res+(dp1[u]-1)-max(0LL,dp2[u]-2));
	chmax(dp3[v],c[v]+res+(dp3[u]-2)-max(0LL,dp2[u]-2));
      }
      sort(w.rbegin(),w.rend());
      
      chmax(dp1[v],c[v]+res);
      chmax(dp2[v],c[v]+res);      
      if(w.size()>1u) chmax(dp3[v],c[v]+res+w[0]+w[1]);

      chmax(ans,dp1[v]);
      chmax(ans,dp2[v]);
      chmax(ans,dp3[v]);      
    };
  
  dfs(0,-1);
  cout<<ans<<endl;
  return 0;
}

