#include<stdio.h>
#include<queue>
using namespace std;
const int inf=2147483647;
int abs(int x){return x>0?x:-x;}
int h[100010],nex[200010],to[200010],M;
void add(int a,int b){
	M++;
	to[M]=b;
	nex[M]=h[a];
	h[a]=M;
}
int v[100010];
struct cmp{
	bool operator()(int x,int y){return v[x]<v[y];}
};
priority_queue<int,vector<int>,cmp>q;
int main(){
	int n,m,i,x,y,head,tail;
	scanf("%d",&n);
	for(i=1;i<n;i++){
		scanf("%d%d",&x,&y);
		add(x,y);
		add(y,x);
	}
	for(i=1;i<=n;i++)v[i]=inf;
	scanf("%d",&m);
	head=1;
	tail=0;
	while(m--){
		scanf("%d%d",&x,&y);
		v[x]=y;
		q.push(x);
	}
	while(!q.empty()){
		x=q.top();
		q.pop();
		for(i=h[x];i;i=nex[i]){
			if(v[to[i]]!=inf){
				if(abs(v[x]-v[to[i]])!=1){
					puts("No");
					return 0;
				}
			}else{
				v[to[i]]=v[x]-1;
				q.push(to[i]);
			}
		}
	}
	puts("Yes");
	for(i=1;i<=n;i++)printf("%d\n",v[i]);
}