#include <cstdio>
#include <vector>
using namespace std;
typedef long long LL;
const int N = 1e5 + 5;
vector <int> G[N];
LL val[N], sum[N];
int deg[N];
int n, flag;
LL dfs(int o, int f){
	LL tmp, mx = -1;
	for(int i = 0; i < G[o].size(); i ++){
		if(G[o][i] == f) continue;
		tmp = dfs(G[o][i], o);
		mx = mx > tmp ? mx : tmp;
		sum[o] += tmp;
	}
	if(deg[o] == 1){
		if(val[o] < sum[o]) flag = 0;
		return val[o] - sum[o];
	}else{
		if(2*val[o] < sum[o]) flag = 0;
		mx = mx > (2*val[o] - sum[o]) ? mx : (2*val[o] - sum[o]);
		if(mx > val[o]) flag = 0;
		return 2*val[o] - sum[o];
	}
}
int main(){
	scanf("%d", &n);
	for(int i = 1; i <= n; i ++) scanf("%I64d", &val[i]);
	for(int i = 1, u, v; i < n; i ++){
		scanf("%d%d", &u, &v);
		G[u].push_back(v);
		G[v].push_back(u);
		deg[u] ++;
		deg[v] ++;
	}
	flag = 1;
	if(dfs(1, -1) != 0) flag = 0;
	puts(flag?"YES":"NO");
}