import std.stdio;
import std.conv, std.array, std.algorithm, std.string;
import std.math, std.random, std.range, std.datetime;
import std.bigint;

class Node{
	static bool cutfailed = false;
	Node[] adjnodes;
	Node parent;
	Node[] kids;
	int id;
	long value;
	this(int id, long value){
		this.id = id;
		this.value = value;
		}
	void add(Node nd){
		this.adjnodes ~= nd;
		nd.adjnodes ~= this;
		}
	void setRoot(){
		foreach(nd; adjnodes) nd.setParent(this);
		}
	void setParent(Node par){
		this.parent = par;
		par.kids ~= this;
		foreach(nd; adjnodes){
			if(nd.id != par.id) nd.setParent(this);
			}
		}
	void cutKids(){
		debug writeln(this.id, ">", nodes.map!(a => a.value), Node.cutfailed);
		foreach(k; kids) if(k.kids.length > 0) k.cutKids();
		long sumvalue = kids.map!(a => a.value).reduce!((a, b) => a + b);
		long maxvalue = kids.map!(a => a.value).reduce!max;
		if(this.parent){
			if(this.value > sumvalue) cutfailed = true;
			else if(this.value < maxvalue) cutfailed = true;
			else if(this.value * 2 < sumvalue) cutfailed = true;
			else{
				this.value = this.value * 2 - sumvalue;
				this.kids.length = 0;
				debug writeln("*", this.value);
				}
			}
		else{ // this is the root
			if(this.kids.length > 1){
				if(this.value * 2 == sumvalue && this.value >= maxvalue){
					this.value = 0;
					this.kids.length = 0;
					debug writeln("*", this.value);
					}
				else cutfailed = true;
				}
			else{
				if(this.value == sumvalue){
					this.value = 0;
					this.kids.length = 0;
					debug writeln("*", this.value);
					}
				else cutfailed = true;
				}
			}
		debug writeln(this.id, "<", nodes.map!(a => a.value), Node.cutfailed);
		}
	}

Node[] nodes;

void main(){
	int n = readln.chomp.to!int;
	long[] as = readln.chomp.split.map!(to!long).array;
	
//	Node[] nodes;
	for(int i = 0; i < n; i ++){
		nodes ~= new Node(i, as[i]);
		}
	
	for(int i = 0; i < n - 1; i ++){
		int[] tmp = readln.chomp.split.map!(to!int).array;
		int a = tmp[0] - 1, b = tmp[1] - 1;
		nodes[a].add(nodes[b]);
		}
	
	nodes[0].setRoot;
	
	debug nodes.map!(a => a.kids.map!(x => x.id)).writeln;
	
	nodes[0].cutKids;
	
	string ans;
	if(Node.cutfailed) ans = "NO";
	else if(nodes[0].adjnodes.length > 1 && nodes[0].value > 0) ans = "NO";
	else ans = "YES";
	
	ans.writeln;
	}
