// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int TAM = 100004;



vector <ll> adj [TAM];

ll val [TAM], pt [TAM];

int n;



void form( int x ){

    int nxt;

    for( int i = 0 ; i < adj[x].size() ; i ++ ){

        nxt = adj[x][i];

        if( nxt == pt[x] ) continue;

        pt[nxt] = x;

        //cout << " parent " << nxt << " = " << pt[nxt] << endl ;

        form(nxt);

    }

}



ll dn, up;

void solve ( ll cap , ll sum ){

    dn = sum - cap;

    up = cap - dn;

}



bool pos = 1;



ll find_up( int x ){

    //cout << " IN " << x << endl ;

    if( adj[x].size() == 1 ) return val[x];

    ll sum = 0, cap = val[x];

    int nxt;

    ll v;

    for( int i = 0 ; i < adj[x].size() ; i ++ ){

        nxt = adj[x][i];

        if( nxt == pt[x] ) continue;

        v = find_up(nxt);

        sum += v;

        if( v > cap ) pos = 0;

        //cout << x << " -> " << nxt << " = " << v << endl ;

    }

    solve( cap , sum );

    if( dn + up != cap or dn < 0 or up < 0 ) pos = 0;

    return up;

}



int main(){



    int a, b;

    scanf("%d",&n);

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

        scanf("%lld",&val[i]);

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

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

        adj[a].push_back(b);

        adj[b].push_back(a);

    }



    if( n == 2 ){

        if( val[1] == val[2] ) printf("YES\n");

        else printf("NO\n");

        return 0;

    }



    int rt;

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

        if( adj[i].size() > 1 ){

            pt [i] = i;

            form(i);

            rt = i;

            break;

        }

    }

    if( !find_up(rt) and pos ) printf("YES\n");

    else printf("NO\n");



    return 0;

}


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

#include <cstdlib>

#include <cstdio>

using namespace std;

inline int read()

{

	int f = 1, x = 0;

	char ch;



	do{

		ch = getchar();

		if (ch == '-')

			f = -1;

	}while(ch < '0' || ch > '9');

	do{

		x = x * 10 + ch - '0';

		ch = getchar();

	}while(ch >= '0' && ch <= '9');

	return f * x;

}

const int N = 1e5;



int n;

int val[N + 1];

struct Edge {

	int to, next;

} edge[(N << 1) + 1];

int start[N + 1], tot;

int d[N + 1], up[N + 1];



inline void addedge(int u, int v)

{

	edge[++tot] = Edge{ v, start[u] };

	start[u] = tot;

	edge[++tot] = Edge{ u, start[v] };

	start[v] = tot;

	d[u]++;

	d[v]++;

	return;

}

inline bool dfs(int u, int fa)

{

	if (d[u] == 1) {

		up[u] = val[u];

		return false;

	}

	int sum = 0, maxx = 0;

	for (int i = start[u]; i; i = edge[i].next) {

		int v = edge[i].to;

		if (v != fa) {

			if (dfs(v, u))

				return true;

			sum += up[v];

			maxx = max(maxx, up[v]);

		}

	}

	up[u] = (val[u] << 1) - sum;

	if (up[u] < 0 || up[u] > val[u] || val[u] < maxx) {

		printf("NO\n");

		return true;

	}

	return false;

}

int main()

{

	n = read();

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

		val[i] = read();

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

		int u = read(), v = read();

		addedge(u, v);

	}

	if (n == 2) {

		if (val[1] == val[2])

			printf("YES\n");

		else

			printf("NO\n");

		return 0;

	}



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

		if (d[i] > 1) {

			if (!dfs(i, 0)) {

				if (up[i])

					printf("NO\n");

				else

					printf("YES\n");

			}

			break;

		}

	}



	return 0;

}


// Fastest known solution for this problem: