import sys

input = sys.stdin.readline

sys.setrecursionlimit(10**7)



N = int(eval(input()))

A = [int(x) for x in input().split()]

UV = [[int(x)-1 for x in row.split()] for row in sys.stdin.readlines()]



if N == 2:

    x,y = A

    answer = 'YES' if x == y else 'NO'

    print(answer)

    exit()



graph = [[] for _ in range(N)]

for u,v in UV:

    graph[u].append(v)

    graph[v].append(u)



def dfs(v,parent=None):

    x = A[v]

    if len(graph[v]) == 1:

        return x

    s = 0

    for w in graph[v]:

        if w == parent:

            continue

        ret = dfs(w,v)

        if ret == None:

            return None

        if x < ret:

            return None

        s += ret

    if 2*x-s > s:

        return None

    if 2*x < s:

        return None

    return 2*x-s



v=0

while len(graph[v]) == 1:

    v += 1



ret = dfs(v)

bl = (ret == 0)



answer = 'YES' if bl else 'NO'

print(answer)
import sys



read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines



N = int(readline())

A = (0, ) + tuple(map(int, readline().split()))

m = list(map(int, read().split()))

G = [[] for _ in range(N + 1)]

for a, b in zip(m, m):

    G[a].append(b)

    G[b].append(a)



def dfs_order(G, root=1):

    parent = [0] * (N + 1)

    order = []

    stack = [root]

    while stack:

        x = stack.pop()

        order.append(x)

        for y in G[x]:

            if y == parent[x]:

                continue

            parent[y] = x

            stack.append(y)

    return parent, order



def main(N, A, G):

    if N == 2:

        return A[1] == A[2]

    degree = [len(x) for x in G]

    root = degree.index(max(degree))

    parent, order = dfs_order(G, root)

    # 上に伸ばすパスの個数

    dp = [0] * (N + 1)

    for v in order[::-1]:

        if degree[v] == 1:

            dp[v] = A[v]

            continue

        p = parent[v]

        nums = [dp[w] for w in G[v] if v != p]

        x = sum(nums)

        y = max(nums)

        pair = x - A[v]

        if pair < 0 or pair > x - y or pair > x // 2:

            return False

        dp[v] = x - 2 * pair

    return dp[root] == 0



print(('YES' if main(N, A, G) else 'NO'))
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10**7)
N = int(eval(input()))
A = [int(x) for x in input().split()]
UV = [[int(x) - 1 for x in row.split()] for row in sys.stdin.readlines()]
if N == 2:
    x, y = A
    answer = "YES" if x == y else "NO"
    print(answer)
    exit()
graph = [[] for _ in range(N)]
for u, v in UV:
    graph[u].append(v)
    graph[v].append(u)


def dfs(v, parent=None):
    x = A[v]
    if len(graph[v]) == 1:
        return x
    s = 0
    for w in graph[v]:
        if w == parent:
            continue
        ret = dfs(w, v)
        if ret == None:
            return None
        if x < ret:
            return None
        s += ret
    if 2 * x - s > s:
        return None
    if 2 * x < s:
        return None
    return 2 * x - s


v = 0
while len(graph[v]) == 1:
    v += 1
ret = dfs(v)
bl = ret == 0
answer = "YES" if bl else "NO"
print(answer)

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
A = (0,) + tuple(map(int, readline().split()))
m = list(map(int, read().split()))
G = [[] for _ in range(N + 1)]
for a, b in zip(m, m):
    G[a].append(b)
    G[b].append(a)


def dfs_order(G, root=1):
    parent = [0] * (N + 1)
    order = []
    stack = [root]
    while stack:
        x = stack.pop()
        order.append(x)
        for y in G[x]:
            if y == parent[x]:
                continue
            parent[y] = x
            stack.append(y)
    return parent, order


def main(N, A, G):
    if N == 2:
        return A[1] == A[2]
    degree = [len(x) for x in G]
    root = degree.index(max(degree))
    parent, order = dfs_order(G, root)
    # 上に伸ばすパスの個数
    dp = [0] * (N + 1)
    for v in order[::-1]:
        if degree[v] == 1:
            dp[v] = A[v]
            continue
        p = parent[v]
        nums = [dp[w] for w in G[v] if v != p]
        x = sum(nums)
        y = max(nums)
        pair = x - A[v]
        if pair < 0 or pair > x - y or pair > x // 2:
            return False
        dp[v] = x - 2 * pair
    return dp[root] == 0


print(("YES" if main(N, A, G) else "NO"))

-input = sys.stdin.readline -sys.setrecursionlimit(10**7) -N = int(eval(input())) -A = [int(x) for x in input().split()] -UV = [[int(x) - 1 for x in row.split()] for row in sys.stdin.readlines()] -if N == 2: -    x, y = A -    answer = "YES" if x == y else "NO" -    print(answer) -    exit() -graph = [[] for _ in range(N)] -for u, v in UV: -    graph[u].append(v) -    graph[v].append(u) +read = sys.stdin.buffer.read +readline = sys.stdin.buffer.readline +readlines = sys.stdin.buffer.readlines +N = int(readline()) +A = (0,) + tuple(map(int, readline().split())) +m = list(map(int, read().split())) +G = [[] for _ in range(N + 1)] +for a, b in zip(m, m): +    G[a].append(b) +    G[b].append(a) -def dfs(v, parent=None): -    x = A[v] -    if len(graph[v]) == 1: -        return x -    s = 0 -    for w in graph[v]: -        if w == parent: -            continue -        ret = dfs(w, v) -        if ret == None: -            return None -        if x < ret: -            return None -        s += ret -    if 2 * x - s > s: -        return None -    if 2 * x < s: -        return None -    return 2 * x - s +def dfs_order(G, root=1): +    parent = [0] * (N + 1) +    order = [] +    stack = [root] +    while stack: +        x = stack.pop() +        order.append(x) +        for y in G[x]: +            if y == parent[x]: +                continue +            parent[y] = x +            stack.append(y) +    return parent, order -v = 0 -while len(graph[v]) == 1: -    v += 1 -ret = dfs(v) -bl = ret == 0 -answer = "YES" if bl else "NO" -print(answer) +def main(N, A, G): +    if N == 2: +        return A[1] == A[2] +    degree = [len(x) for x in G] +    root = degree.index(max(degree)) +    parent, order = dfs_order(G, root) +    # 上に伸ばすパスの個数 +    dp = [0] * (N + 1) +    for v in order[::-1]: +        if degree[v] == 1: +            dp[v] = A[v] +            continue +        p = parent[v] +        nums = [dp[w] for w in G[v] if v != p] +        x = sum(nums) +        y = max(nums) +        pair = x - A[v] +        if pair < 0 or pair > x - y or pair > x // 2: +            return False +        dp[v] = x - 2 * pair +    return dp[root] == 0 + + +print(("YES" if main(N, A, G) else "NO"))