#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
int head[100005],arrive[200005],nxt[200005],tot;
void add_edge(int from,int to){
	arrive[++tot]=to;
	nxt[tot]=head[from];
	head[from]=tot;
}
struct Node{
	int id;
	int value;
	friend bool operator >(Node p,Node q){
		return p.value>q.value;
	}
};
priority_queue<Node,vector<Node>,greater<Node> > q;
int value[100005];
int ab(int a){
	return a<0?-a:a;
}
int main(){
	int n;
	scanf("%d",&n);
	int u,v;
	for(int i=1;i<n;i++){
		scanf("%d%d",&u,&v);
		add_edge(u,v);
		add_edge(v,u);
	}
	memset(value,-1,sizeof value);
	int k;
	scanf("%d",&k);
	for(int i=1;i<=k;i++){
		scanf("%d%d",&u,&v);
		value[u]=v;
		q.push((Node){u,v});
	}
	while(!q.empty()){
		u=q.top().id;
		v=q.top().value;
		q.pop();
		for(int i=head[u];i;i=nxt[i]){
			if(value[arrive[i]]!=-1){
				continue;
			}
			value[arrive[i]]=v+1;
			q.push((Node){arrive[i],v+1});
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=head[i];j;j=nxt[j]){
			if(ab(value[i]-value[arrive[j]])!=1){
				puts("No");
				return 0;
			}
		}
	}
	puts("Yes");
	for(int i=1;i<=n;i++){
		printf("%d\n",value[i]);
	}
	return 0;
}
