You are given a tree with N vertices, numbered 1 through N. Each of the N-1 edges connects vertices a_i and b_i. There are A_i stones placed on vertex i. Determine if it's possible to remove all stones by repeatedly selecting a pair of different leaves and removing one stone from every vertex on the path between those two vertices. The operation cannot be performed if there is a vertex with no stone on the path. Constraints: 2 ≤ N ≤ 10^5, 1 ≤ a_i, b_i ≤ N, 0 ≤ A_i ≤ 10^9, and the given graph is a tree. Input is given in the format: N, A_1, A_2, ..., A_N, a_1, b_1, ..., a_{N-1}, b_{N-1}. Output "YES" if it's possible to remove all stones, otherwise output "NO".

# Buggy version:
import sys
sys.setrecursionlimit(500000)
N = int(input())
A = [0] + list(map(int, input().split()))
E = [[] for _ in range(N+1)]
for _ in range(N-1):
    a, b = map(int, input().split())
    E[a].append(b)
    E[b].append(a)

def dfs(v, p=0):
    a = A[v]
    b = []
    for u in E[v]:
        if u!=p:
            b.append(dfs(u, v))
    if len(b)==0:
        return a
    sum_b, max_b = sum(b), max(b)
    if a < 2*max_b-sum_b or a < 2*sum_b or a > sum_b:
        print("NO")
        exit()
    return 2 * a - sum_b

ans = dfs(1)
if (ans==0 and len(E[1])>1) or (ans==A[1] and len(E[1])==1):
    print("YES")
else:
    print("NO")


# Fixed version:
import sys
sys.setrecursionlimit(500000)
N = int(input())
A = [0] + list(map(int, input().split()))
E = [[] for _ in range(N+1)]
for _ in range(N-1):
    a, b = map(int, input().split())
    E[a].append(b)
    E[b].append(a)

def dfs(v, p=0):
    a = A[v]
    b = []
    for u in E[v]:
        if u!=p:
            b.append(dfs(u, v))
    if len(b)==0:
        return a
    sum_b, max_b = sum(b), max(b)
    if a < max_b or 2 * a < sum_b or a > sum_b:
        print("NO")
        exit()
    return 2 * a - sum_b

v = 1
ans = dfs(v)
if (ans==0 and len(E[v])>1) or (ans==A[v] and len(E[v])==1):
    print("YES")
else:
    print("NO")

# Buggy version:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    n = I()
    a = LI()
    e = collections.defaultdict(list)
    for _ in range(n-1):
        b,c = LI_()
        e[b].append(c)
        e[c].append(b)

    if n == 2:
        if a[0] == a[1]:
            return 'YES'
        return 'NO'

    def f(c, p):
        t = []
        ac = a[c]
        for d in e[c]:
            if d == p:
                continue
            r = f(d, c)
            if not r:
                return
            t.append(r)

        if not t:
            return ac

        ts = sum(t)
        ma = min(ts//2, max(t))
        at = ts - ac
        if at > ma or at < 0:
            return
        return ac - at

    for i in range(n):
        if len(e[i]) == 1:
            continue
        r = f(i,-1)
        if r == 0:
            return 'YES'
        return 'NO'

    return 'NO'




print(main())






# Fixed version:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    n = I()
    a = LI()
    e = collections.defaultdict(list)
    for _ in range(n-1):
        b,c = LI_()
        e[b].append(c)
        e[c].append(b)

    if n == 2:
        if a[0] == a[1]:
            return 'YES'
        return 'NO'

    def f(c, p):
        t = []
        ac = a[c]
        for d in e[c]:
            if d == p:
                continue
            r = f(d, c)
            if not r and r != 0:
                return
            t.append(r)

        if not t:
            return ac

        ts = sum(t)
        ma = min(ts//2, ts-max(t))
        at = ts - ac
        if at > ma or at < 0 or at > ac:
            return
        return ac - at

    for i in range(n):
        if len(e[i]) == 1:
            continue
        r = f(i,-1)
        if r == 0:
            return 'YES'
        return 'NO'

    return 'NO'




print(main())