#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
using namespace std;
#define N 100050
int head[N],to[N<<1],nxt[N<<1],cnt,n,K,is[N],vv[N],dep[N],root,need[N],mn[N],ans[N],siz[N];
void gun() {puts("No"); exit(0);}
inline void add(int u,int v) {
	to[++cnt]=v; nxt[cnt]=head[u]; head[u]=cnt;
}
void d1(int x,int y) {
	int i;
	dep[x]=dep[y]+1;
	if(is[x]) {
		int tmp=vv[root]+dep[x]-vv[x];
		if(tmp<0||(tmp&1)) gun();
		need[x]=tmp>>1;
		mn[x]=need[x];
	}else mn[x]=1<<30;
	siz[x]=is[x];
	for(i=head[x];i;i=nxt[i]) if(to[i]!=y) {
		d1(to[i],x); siz[x]+=siz[to[i]]; mn[x]=min(mn[x],mn[to[i]]);
	}
}
void d2(int x,int y,int now) {
	int i;
	if(is[x]) {
		if(need[x]==now+1) now++;
		else if(need[x]>now+1) gun();
		
		
		if(need[x]!=now) gun();
		ans[x]=vv[x];
	}else {
		if(siz[x]&&mn[x]>now) {
			ans[x]=ans[y]-1;
			now++;
		}else {
			ans[x]=ans[y]+1;
		}
	}
	for(i=head[x];i;i=nxt[i]) if(to[i]!=y) {
		d2(to[i],x,now);
	}
}
int main() {
	scanf("%d",&n);
	int i,x,y;
	for(i=1;i<n;i++) scanf("%d%d",&x,&y),add(x,y),add(y,x);
	scanf("%d",&K);
	for(i=1;i<=K;i++) {
		scanf("%d%d",&x,&y); is[x]=1; vv[x]=y; root=x;
	}
	dep[0]=-1;
	d1(root,0);
	d2(root,0,0);
	puts("Yes");
	for(i=1;i<=n;i++) printf("%d\n",ans[i]);
}
