#include<iostream>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#define fo(i,a,b) for(i=a;i<=b;i++)
#define fod(i,a,b) for(i=a;i>=b;i--)
#define rep(i,a) for(i=first[a];i;i=next[i])
using namespace std;
typedef long long ll;
const int maxn=2e5+7;
int i,j,k,l,t,n,m;
int first[maxn*2],last[maxn*2],next[maxn*2],num;
ll a[maxn],f[maxn],g[maxn],b,c,ans;
ll d[maxn],qian[maxn],hou[maxn];
ll qc[maxn],hc[maxn],p[maxn];
ll da1,cda1;
void add(int x,int y){
last[++num]=y,next[num]=first[x],first[x]=num;
}
void dfs(int x,int y){
int i;
ll da=0,cda=0,yi=0,er=0;
rep(i,x){
if(last[i]!=y){
dfs(last[i],x);
g[x]=max(g[x],g[last[i]]);
f[x]=max(f[x],f[last[i]]);
if(da<g[last[i]])cda=da,da=g[last[i]];
else if(g[last[i]]>cda)cda=g[last[i]];
if(yi<f[last[i]])er=yi,yi=f[last[i]];
else if(f[last[i]]>er)er=f[last[i]];
}
}
g[x]+=a[x];
f[x]=max(f[x],a[x]+da+cda);
ans=max(ans,yi+er);
}
void dfs1(int x,int y,ll z){
int i,j;
ll da=0,cda=0;
rep(i,x){
if(last[i]!=y){
if(da<g[last[i]])cda=da,da=g[last[i]];
else if(g[last[i]]>cda)cda=g[last[i]];
}
}
rep(i,x){
if(last[i]!=y){
if(g[last[i]]==da){
if(z<cda)dfs1(last[i],x,cda+a[x]);
else dfs1(last[i],x,z+a[x]);
}
else{
if(z<da)dfs1(last[i],x,da+a[x]);
else dfs1(last[i],x,z+a[x]);
}
}
}
d[0]=0;
rep(i,x)if(last[i]!=y)d[++d[0]]=last[i];
qian[0]=qc[0]=0;
hou[d[0]+1]=hc[d[0]+1]=0;
if(x==4){
ans=ans;
}
fo(i,1,d[0]){
if(g[d[i]]>qian[i-1])qc[i]=qian[i-1],qian[i]=g[d[i]];
else if(g[d[i]]>qc[i-1])qian[i]=qian[i-1],qc[i]=g[d[i]];
else qian[i]=qian[i-1],qc[i]=qc[i-1];
}
fod(i,d[0],1){
if(g[d[i]]>hou[i+1])hc[i]=hou[i+1],hou[i]=g[d[i]];
else if(g[d[i]]>hc[i+1])hou[i]=hou[i+1],hc[i]=g[d[i]];
else hou[i]=hou[i+1],hc[i]=hc[i+1];
}
fo(i,1,d[0]){
da=cda=0;
if(qian[i-1]>da)cda=da,da=qian[i-1];
else if(qian[i-1]>cda)cda=qian[i-1];
if(qc[i-1]>da)cda=da,da=qc[i-1];
else if(qc[i-1]>cda)cda=qc[i-1];
if(hou[i+1]>da)cda=da,da=hou[i+1];
else if(hou[i+1]>cda)cda=hou[i+1];
if(hc[i+1]>da)cda=da,da=hc[i+1];
else if(hc[i+1]>cda)cda=hc[i+1];
ans=max(ans,da+cda+a[x]+f[d[i]]);
ans=max(ans,z+a[x]+da+f[d[i]]);
}
}
int main(){
// freopen("fan.in","r",stdin);
scanf("%d",&n);
fo(i,1,n)scanf("%d",&a[i]);
fo(i,1,n-1){
scanf("%d%d",&k,&l);
add(k,l),add(l,k);
}
dfs(1,0);
dfs1(1,0,0);
printf("%lld\n",ans);
}