#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <cstring>
#include <climits>
#include <string.h>
#include <stdio.h>
#define LL long long
#define all(x) (x).begin(),(x).end()
#define pii pair<int,int>
#define piii pair<int, pii >
#define REP(i,n) for (int (i)=0;(i)<(n);(i)++)
#define vi vector<int>
#define vpi vector< pii >
#define INF 2147483647
#define big 19260817
#define pb push_back
#define mp make_pair
using namespace std;
const int Maxk=1005;
string mul(string a,string b){
	int res[Maxk];
	memset(res,0,sizeof(res));
	reverse(a.begin(),a.end());
	reverse(b.begin(),b.end());
	for (int i=0;i<a.length();i++){
		for (int j=0;j<b.length();j++){
			res[i+j]+=(a[i]-'0')*(b[j]-'0');
		}
	}
	for (int i=0;i<Maxk;i++){
		if (res[i]>=10) {
			res[i+1]+=(res[i]/10);
			res[i]%=10;
		}
	}
	string ret;
	bool flag=false;
	for (int i=Maxk-1;i>=0;i--){
		if (flag || res[i]){
			flag=true;
			ret=ret+(char)(res[i]+'0');
		}
	}
	if (ret=="") ret="0";
	return ret;
}
string add(string a,string b){
	if (a.length()<b.length()) swap(a,b);
	while (a.length()!=b.length()){
		b='0'+b;
	}
	for (int i=a.length()-1;i>=0;i--){
		a[i]+=(b[i]-'0');
		if (a[i]>'9' && i){
			a[i]-=10;
			a[i-1]++;
		}
	}
	if (a[0]>'9'){
		a[0]-=10;
		a='1'+a;
	}
	return a;
}
// cf IO: I64d
// atcoder IO: ｌｌｄ
const int Maxn=100005;
pair<int,int> dp[Maxn];
vector<int> G[Maxn];
int val[Maxn];
bool vis[Maxn];
pair<int,int> inter(pair<int,int> x,pair<int,int> y){
	if (x.first==-1e9 || y.first==-1e9) return mp(-1e9,-1e9);
	if (x.first>y.first) swap(x,y);
	if (x.second<y.first) return mp(-1e9,-1e9);
	return mp(y.first,min(x.second,y.second)); 
}
void dfs(int x){
	vis[x]=true;
	int lf=-1e8,rg=1e8;
	vector<int> xx;
	if (val[x]!=-1) lf=val[x],rg=val[x];
	for (int i=0;i<G[x].size();i++){
		int v=G[x][i];
		if (vis[v]) continue;
		dfs(v);
		if (dp[v].first==dp[v].second) xx.push_back(dp[v].first);
		pii tmp=inter(mp(lf,rg),mp(dp[v].first-1,dp[v].second+1));
		lf=tmp.first,rg=tmp.second;
	}
	if (lf==-1e9){
		printf("No\n");
		exit(0);
	}
	sort(xx.begin(),xx.end());
	xx.resize(unique(xx.begin(),xx.end())-xx.begin());
	dp[x]=mp(lf,rg);
}
void dfs2(int x,int lo,int hi){
	dp[x]=inter(dp[x],mp(lo,hi));
	val[x]=dp[x].first;
	vis[x]=true;
	for (int i=0;i<G[x].size();i++){
		int v=G[x][i];
		if (vis[v]) continue;
		dfs2(v,dp[x].first-1,dp[x].first+1);
	}
}
void check(int x,int f){
	vis[x]=true;
	if (val[x]!=-1){
		if (f!=-1 && val[x]%2!=f){
			printf("No\n");
			exit(0);
		}
		f=val[x]%2;
		f=!f;
	}
	else if (f!=-1) f=!f;
	for (int i=0;i<G[x].size();i++){
		int v=G[x][i];
		if (!vis[v]) check(v,f);
	}
}
int main(){
	memset(val,-1,sizeof(val));
	int n,k;
	scanf("%d",&n);
	for (int i=0;i<n-1;i++){
		int u,v;
		scanf("%d %d",&u,&v);
		G[u].pb(v);
		G[v].pb(u);
	}
	scanf("%d",&k);
	memset(val,-1,sizeof(val));
	for (int i=1;i<=k;i++){
		int x,y;
		scanf("%d %d",&x,&y);
		val[x]=y;
	}
	memset(vis,false,sizeof(vis));
	check(1,-1);
	memset(vis,false,sizeof(vis));
	dfs(1);
	printf("Yes\n");
	memset(vis,false,sizeof(vis));	
	dfs2(1,-1e8,1e8);
	for (int i=1;i<=n;i++){
		printf("%d\n",val[i]);
	}
	return 0;
}

Measured memory_bytes: 18560