import scala.collection.mutable
import java.util.Scanner

/**
 * Created by sonetsuyoshi on 2015/12/16.
 */

case class Node(id: Int, nRock: Long, children: Seq[Node]) {
  def hasChild() = children.size > 0
}

object Main extends App {
  val sc = new Scanner(System.in)
  val n = sc.nextInt
  val a = Array.fill(n)(sc.nextLong)
  val connectMap = new mutable.HashMap[Int, Set[Int]] with mutable.MultiMap[Int, Int]
  for(i <- 0 until n - 1) {
    val x = sc.nextInt - 1
    val y = sc.nextInt - 1
    connectMap.addBinding(x, y)
    connectMap.addBinding(y, x)
  }

  run()

  def isConnected(x : Int, y: Int) = {
    connectMap.entryExists(x, _ == y)
  }

  def constructNode(node: Int, parent: Option[Int] = None): Node = {
    val childrenIds = 0.until(n).filter(i => Some(i) != parent && isConnected(node, i))
    if(childrenIds.size == 0) Node(node, a(node), List())
    else Node(node, a(node), childrenIds.map(constructNode(_, Some(node))))
  }

  def run(): Unit = {
    val nodes = Array.ofDim[Node](n)

    val root = constructNode(0)

    def solve(node: Node): Long = {
      if(node.hasChild()) {
        val s = node.children.foldLeft(0.toLong)((s, child) => s + solve(child))
        2 * node.nRock - s
      } else node.nRock
    }

    val ans = solve(root)
    if(root.children.size == 1 && ans == root.nRock || root.children.size > 0 && ans == 0) println("YES")
    else println("NO")
  }
}
