#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define inf 0x3f3f3f3ftypedef long long ll;using namespace std;int dp[100010][2],head[100010],vis[100010],ct,n,m;struct edge{int tonode;//这条边指向的结点int nextedge;//这条边指向的下一条边}G[400040];void add(int a,int b){G[ct].tonode&#61;b;G[ct].nextedge&#61;head[a];head[a]&#61;ct&#43;&#43;;G[ct].tonode&#61;a;G[ct].nextedge&#61;head[b];head[b]&#61;ct&#43;&#43;;}void dfs(int x){vis[x]&#61;1;for(int i&#61;head[x];i!&#61;-1;i&#61;G[i].nextedge){int v&#61;G[i].tonode;if(vis[v])continue;dfs(v);//搜下一条边dp[x][1]&#43;&#61;dp[v][0];//此层取下一层不取dp[x][0]&#43;&#61;max(dp[v][0],dp[v][1]);//此层不取&#xff0c;下一层取和不取的最大值}}int main(){cin>>n;for(int i&#61;1;i<&#61;n;i&#43;&#43;)cin>>dp[i][1];memset(head,-1,sizeof(head));m&#61;n-1;while(m--){int a,b;cin>>a>>b;add(a,b);}dfs(1);cout<}