#include<bits/stdc++.h>
#include<string.h>
using namespace std;
const int N=1e5+6;
int head[N],tot=0;
struct node{
int to,next;
}edge[2*N];
void add(int from,int to){
++tot;
edge[tot].to=to;
edge[tot].next=head[from];
head[from]=tot;
}
int f[N][2];
int n,r[N],l,k;
int dfs(int x){
f[x][0]=0;
f[x][1]=r[x];
for(int i=head[x];i;i=edge[i].next){
int y=edge[i].to;
dfs(y);
f[x][0]+=max(f[y][0],f[y][1]);
f[x][1]+=f[y][0];
}
}
int main()
{
cin>>n;
for(int i=1;i<=n;i++)cin>>r[i];
for(int i=1;i<n;i++)
{
cin>>l>>k;
add(k,l);
}
dfs(1);
cout<<max(f[1][0],f[1][1]);
return 0;
}
请帮忙看一下