// Original C++ solution (slower):
//http://agc010.contest.atcoder.jp/tasks/agc010_c?lang=en



#include <bits/stdc++.h>



using namespace std;



typedef pair< int, int > pii;

typedef long long ll;



const int MAXN = 1e5 + 10;

int n, A[ MAXN ], deg[ MAXN ];

vector< int > graph[ MAXN ];

map< pii, ll > edge;

bool visited[ MAXN ];





bool check( int u ){

	if( graph[ u ].size() == 1 ) return edge[ make_pair( min( u, graph[ u ][ 0 ] ), max( u, graph[ u ][ 0 ] ) ) ] == A[ u ];

	ll sum = 0;

	for( int i = 0; i < graph[ u ].size(); ++i ){

		ll val = edge[ make_pair( min( u, graph[ u ][ i ] ), max( u, graph[ u ][ i ] ) ) ];

		if( val > A[ u ] ) return false;

		sum += val;

	}

	return sum == (A[ u ] << 1);

}



int main(){

	scanf( "%d", &n );

	for( int i = 1; i <= n; ++i ) scanf( "%d", &A[i] );

	for( int i = 1, a, b; i < n; ++i ){

		scanf( "%d%d", &a, &b );

		graph[ a ].push_back( b );

		graph[ b ].push_back(  a );

		++deg[ a ]; ++deg[ b ];

	}

	queue< int > q;

	for( int i = 1; i <= n; ++i )

		if( deg[ i ] == 1 ) q.push( i );



	bool flag = true;



	while( flag && !q.empty() ){

		int u = q.front(); q.pop();

		//cout << u << endl;

		visited[ u ] = true;

		ll sum = 0; int v = -1;

		for( int i = 0; i < graph[ u ].size(); ++i ){

			int ne = graph[ u ][ i ];

			if( visited[ ne ] ) sum += edge[ make_pair( min( u, ne ), max( ne, u ) ) ];

			else v = ne;

		}

		if( v != -1 ){

			--deg[ v ];

			if( deg[ v ] == 1 ) q.push( v );

			if( graph[ u ].size() == 1 ){

				edge[ make_pair( min( u, v ), max( u, v ) ) ] = A[ u ];

			}

			else{

				if( (A[ u ] << 1) < sum ) flag = false;

				else edge[ make_pair( min( u, v ), max( u, v ) ) ] = (A[ u ] << 1) - sum;

			}

		}

	}



	/*for( map< pii, ll >::iterator it = edge.begin(); it != edge.end(); ++it ){

		cout << (it->first).first << '-' << (it->first).second << ": " << it->second << endl;

	}*/



	if( flag )

		for( int i = 1; i <= n && flag; ++i )

			flag  = check( i );



	if( flag ) puts( "YES" );

	else puts( "NO" );



	return 0;

}

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <algorithm>

#define int long long

using namespace std;

typedef long long LL;

const int MAXN = 1e5 + 5;

int n;

int head[MAXN] , to[MAXN << 1] , nxt[MAXN << 1] , cnt , ans , du[MAXN << 1];

LL f[MAXN] , a[MAXN];

void add(int u , int v) {nxt[++cnt] = head[u];head[u] = cnt;to[cnt] = v;}

void dfs(int x , int fa) {

	LL _sum = 0 , mx = 0;

	for (int i = head[x]; i; i = nxt[i]) {

		if(to[i] == fa) continue;

		dfs(to[i] , x);

		if(ans) return;

		mx = max(mx , f[to[i]]);

		_sum += f[to[i]];

	}

	if(!_sum) {

		f[x] = a[x];

		return;

	}

	f[x] = 2ll * a[x] - _sum;

	if(f[x] < 0 || f[x] > a[x] || mx - f[x] > _sum - mx || a[x] < mx) {

		printf("NO");

		exit(0);

	}

}

signed main() {

	scanf("%lld" , &n);

	for (int i = 1; i <= n; ++i) scanf("%lld" , &a[i]);

	if (n == 2) return puts(a[1] == a[2] ? "YES" : "NO"), 0;

	int root = 0;

	for (int i = 1; i < n; ++i) {

		int u , v;

		scanf("%lld %lld" , &u , &v);

		du[u] ++;du[v] ++;

		add(u , v);add(v , u);

		if(du[u] > 1) root = u;

		if(du[v] > 1) root = v;

	}

	dfs(root , 0);

	if(f[root]) printf("NO");

	else printf("YES");

	return 0;

}

// Fastest known solution for this problem: