module e;
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{
	int id;
	Node[] adjnodes;
	int x;
	int _value;
	bool hasValue = false;
	int color = 0; // 0: undef, 1: black, 2: white
	int min = 0, max = 1_000_000;
	int tmpmin, tmpmax;
	static hasError = false;
	this(int id){
		this.id = id;
		x = uniform(0, 100000);
		}
	void add(Node nd){
		this.adjnodes ~= nd;
		nd.adjnodes ~= this;
		}
	void setColor(int c){
		if(this.color > 0) return;
		this.color = c;
		foreach(nd; adjnodes) nd.setColor(1 + 2 - c);
		}
	int value(int v){
		this._value = v;
		this.hasValue = 1;
		return _value;
		}
	int value(){	
		return _value;
		}
	void start(){
		Node[] q = [this];
		while(q.length){
			Node nd = q[0];
			q = q[1 .. $];
			debug writeln("- ", [nd.id, nd.min, nd.max, nd.tmpmin, nd.tmpmax]);
			if(nd.min < nd.tmpmin || nd.max > nd.tmpmax){
				if(nd.min > nd.tmpmax || nd.max < nd.tmpmin){
					hasError = true;
					return;
					}
				if(nd.min < nd.tmpmin) nd.min = nd.tmpmin;
				if(nd.max > nd.tmpmax) nd.max = nd.tmpmax;
				debug writeln("  ", [nd.id, nd.min, nd.max, nd.tmpmin, nd.tmpmax]);
				foreach(nd2; nd.adjnodes){
					nd2.tmpmin = nd.min - 1, nd2.tmpmax = nd.max + 1;
					q ~= nd2;
					debug writeln("+ ", [nd2.id, nd2.min, nd2.max, nd2.tmpmin, nd2.tmpmax]);
					}
				}
			}
		}
	}

void main(){
	int n = readln.chomp.to!int;
	
	Node[] nodes;
	foreach(i; 0 .. n) nodes ~= new Node(i + 1);
	foreach(i; 0 .. n - 1){
		int[] tmp = readln.chomp.split.map!(to!int).map!(x => x - 1).array;
		nodes[tmp[0]].add(nodes[tmp[1]]);
		}
	
	Node[] valuednodes;
	int k = readln.chomp.to!int;
	foreach(i; 0 .. k){
		int[] tmp = readln.chomp.split.map!(to!int).array;
		tmp[0] -= 1;
		nodes[tmp[0]].value = tmp[1];
		valuednodes ~= nodes[tmp[0]];
		}
	
	valuednodes.sort!("a.x < b.x")();
	
	valuednodes[0].setColor((valuednodes[0].value % 2)? 1: 2);
	foreach(nd; valuednodes) if(nd.color != ((nd.value % 2)? 1: 2)){
		"No".writeln;
		return;
		}
	
	foreach(nd; valuednodes){
		nd.tmpmin = nd.value, nd.tmpmax = nd.value;
		nd.start;
		if(Node.hasError){
			"No".writeln;
			return;
			}
		}
	
	"Yes".writeln;
	foreach(nd; nodes) nd.max.writeln;
	
	}
