#include <bits/stdc++.h>
using namespace std;
int mx[100010],mn[100010],head[100010],o=0,k,n,t,a[100010],up_mx[100010],up_mn[100010];
bool sure[100010];
struct edge{
	int to,link;
}e[200010];
void add_edge(int u,int v){
	e[++o].to=v,e[o].link=head[u],head[u]=o;
	e[++o].to=u,e[o].link=head[v],head[v]=o;
}
void dfs(int u,int pre,int down_mx,int down_mn){
	if(sure[u]) down_mx=mx[u],down_mn=mn[u],up_mx[u]=mx[u]+1,up_mn[u]=mn[u]-1;
	else mx[u]=down_mx,mn[u]=down_mn;
	for(int i=head[u];i;i=e[i].link){
		if(e[i].to==pre) continue;
		dfs(e[i].to,u,down_mx+1,down_mn-1);
		mx[u]=min(mx[u],up_mx[e[i].to]),mn[u]=max(mn[u],up_mn[e[i].to]);
	}
	up_mx[u]=mx[u]+1,up_mn[u]=mn[u]-1; 
}
void work(int u,int pre,int now){
	a[u]=now;
	for(int i=head[u];i;i=e[i].link){
		if(e[i].to==pre) continue;
		if(now-1>=mn[e[i].to]) work(e[i].to,u,now-1);
		else work(e[i].to,u,now+1);
	}
}
int main(){
	scanf("%d",&n);
	for(int i=1,u,v;i<n;i++) scanf("%d %d",&u,&v),add_edge(u,v);
	scanf("%d",&k);
	for(int i=1,v,p;i<=k;i++) scanf("%d %d",&v,&p),mx[v]=mn[v]=p,t=v,sure[v]=true;
	dfs(t,0,1e6,-1e6);
	for(int i=1;i<=n;i++) if(mx[i]<mn[i]){
		printf("No\n");
		return 0;
	}
	work(t,0,mx[t]);
	for(int i=1;i<=n;i++) if(a[i]>mx[i]){
		printf("No\n");
		return 0;
	}
	printf("Yes\n");
	for(int i=1;i<=n;i++) printf("%d\n",a[i]);
} 