#include <cstdio>
#include <queue>

using std::priority_queue;

const int MAXN=100011;

int abs(int a){
	return (a>0)?a:(-a);
}

int N, K;

struct Vert{
	int FE;
	int Val;
	bool Vis;
} V[MAXN];

struct Edge{
	int y, next;
} E[MAXN<<1];

int Ecnt;

void addE(int a, int b){
	++Ecnt;
	E[Ecnt].y=b;E[Ecnt].next=V[a].FE;V[a].FE=Ecnt;
}

struct Pair{
	int p, v;
	Pair(){}
	Pair(int _p, int _v){p=_p;v=_v;}
};

bool operator < (Pair A, Pair B){
	return A.v<B.v;
}

priority_queue<Pair> PQ;



int main(){
	
	scanf("%d", &N);
	
	for(int i=1, a, b;i<N;++i){
		scanf("%d %d", &a, &b);
		addE(a, b);addE(b, a);
	}
	
	scanf("%d", &K);
	
	for(int i=1, p, v;i<=K;++i){
		scanf("%d%d", &p, &v);
		V[p].Val=v;V[p].Vis=true;
		PQ.push(Pair(p, v));
	}
	
	for(Pair P;!PQ.empty();){
		P=PQ.top();PQ.pop();
		int &at=P.p;
		for(int k=V[at].FE, to;k;k=E[k].next){
			to=E[k].y;
			if(V[to].Vis)	continue;
			V[to].Val=V[at].Val-1;
			V[to].Vis=true;
			PQ.push(Pair(to, V[to].Val));
		}
	}
	
	bool ret=true;
	for(int i=1;i<=Ecnt;i+=2){
		ret&=abs(V[E[i].y].Val-V[E[i+1].y].Val)==1;
	}
	
	if(!ret)	puts("No");
	else{
		puts("Yes");
		for(int i=1;i<=N;++i)	printf("%d\n", V[i].Val);
	}
	
	
	return 0;
}