#include<string.h>
#define N 6100
int a[N];
int dp[N][2];
struct node {
int u,v,w,next;
}bian[N*2];
int head[N],yong,visit[N];
void addedge(int u,int v) {
bian[yong].v=v;
bian[yong].next=head[u];
head[u]=yong++;
}
int M (int a,int b) {
return a>b?a:b;
}
int dfs(int u) {
int i,j;
dp[u][0]=0;
dp[u][1]=a[u];
visit[u]=1;
for(i=head[u];i!=-1;i=bian[i].next) {
j=bian[i].v;
if(!visit[j]) {
dp[u][0]+=dfs(j);
dp[u][1]+=dp[j][0];
}
}
return M(dp[u][0],dp[u][1]);
}
int main() {
int n,i,x,y;
while(scanf("%d",&n)!=EOF) {
yong=0;
memset(visit,0,sizeof(visit));
memset(head,-1,sizeof(head));
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
while(scanf("%d%d",&x,&y),x||y) {
addedge(y,x);
addedge(x,y);
}
memset(dp,0,sizeof(dp));
printf("%d\n",dfs(3));
}
return 0;
}