#include <bits/stdc++.h>
            #include<iostream>
            #include<cstdio>
            #include<vector>
            #include<queue>
            #include<map>
            #include<cstring>
            #include<string>
            #include <math.h>
            #include<algorithm>
        //    #include <boost/multiprecision/cpp_int.hpp>
            #include<functional>
          #define int long long
            #define inf  1000000007
            #define pa pair<int,int>
    #define ll long long
            #define pal pair<ll,ll>
            #define ppa pair<int,pa>
            #define  mp make_pair
            #define EPS (1e-10)
            #define equals(a,b) (fabs((a)-(b))<EPS)
     
            using namespace std;
     
            class Point{
            	public:
            	double x,y;
            	Point(double x=0,double y=0):x(x),y(y) {}
            	Point operator + (Point p) {return Point(x+p.x,y+p.y);}
            	Point operator - (Point p) {return Point(x-p.x,y-p.y);}
            	Point operator * (double a) {return Point(x*a,y*a);}
            	Point operator / (double a) {return Point(x/a,y/a);}
            	double absv() {return sqrt(norm());}
            	double norm() {return x*x+y*y;}
            	bool operator < (const Point &p) const{
            		return x != p.x ? x<p.x: y<p.y;
            	}
            	bool operator == (const Point &p) const{
            		return fabs(x-p.x)<EPS && fabs(y-p.y)<EPS;
            	}
            };
            typedef Point Vector;
     
            struct Segment{
            Point p1,p2;
            };
     
        double hen(Vector a){
        if(fabs(a.x)<EPS && a.y>0) return acos(0);
        else if(fabs(a.x)<EPS && a.y<0) return 3*acos(0);
        else if(fabs(a.y)<EPS && a.x<0) return 2*acos(0);
        else if(fabs(a.y)<EPS && a.x>0) return 0.0;
        else if(a.y>0) return acos(a.x/a.absv());
        else return 2*acos(0)+acos(-a.x/a.absv());
     
        }
     
            double dot(Vector a,Vector b){
            	return a.x*b.x+a.y*b.y;
            }
            double cross(Vector a,Vector b){
            	return a.x*b.y-a.y*b.x;
            }
        
            //----------------kokomade temple------------
int n,m,k,x,t,r;
vector<int> G[100002];
bool ok=true;
vector<int> G2[100002];
int v[100002],sita[100002],ue[100002],w[100002]={0};
int guu[100002]={0};
bool sumi[100002]={0};
void saiki(int u,int mae){
	if(mae==0){
		guu[u]=v[u]%2;
	}
	for(int i=0;i<G[u].size();i++){
		if(G[u][i]==mae) continue;
		guu[G[u][i]]=1-guu[u];
		G2[u].push_back(G[u][i]);
		saiki(G[u][i],u);
	}
	
}

pa xc(int i){
	if(sumi[i]==1){ 
		w[i]=1;
		sita[i]=v[i];
		ue[i]=v[i];
		return mp(v[i],v[i]);
	}
	else if(G2[i].size()==0){
		w[i]=1;
		sita[i]=-inf/10;
		ue[i]=inf/10;
		return mp(sita[i],ue[i]);
	}
		if(w[i]==1) return mp(sita[i],ue[i]);
	
	int lo=-inf/10,ma=inf/10;
	for(int j=0;j<G2[i].size();j++){
		pa z=xc(G2[i][j]);
		lo=max(lo,z.first);
		ma=min(ma,z.second);
		
	}
	lo--;
	ma++;
//	cout<<" "<<i<<" "<<lo<<" "<<ma<<endl;
	if(lo>ma) ok=false;
	sita[i]=lo,ue[i]=ma;
	w[i]=1;
	return mp(lo,ma);
}


void sai(int i){
	for(int j=0;j<G2[i].size();j++){
		sai(G2[i][j]);
	}
	pa z=xc(i);
	if(z.first>z.second)ok=false;
	if(sumi[i]){
		if(!(z.first<=v[i] && v[i]<= z.second)) {
			ok=false;
			return;
		}
	}
	
}
int ans[100002];
void saikiz(int i,int oya){
	if(oya!=0)	if(ue[i]+1<sita[oya]|| ue[oya]+1 < sita[i]) ok=false;
	
	if(oya==0){
		ans[i]=v[i];
	}
	else{
		if(ans[oya]-1>=sita[i]) ans[i]=ans[oya]-1;
		else ans[i]=ans[oya]+1;
	}
	for(int j=0;j<G2[i].size();j++) saikiz(G2[i][j],i);
	return;
}
    signed main(){
    	
    	cin>>n;
    	for(int i=1;i<n;i++){
    		int zz,zzz;
    		cin>>zz>>zzz;
    		G[zz].push_back(zzz);
    		G[zzz].push_back(zz);
    	}
    	
    	int rr;
		cin>>k;
    	for(int i=1;i<=k;i++){
    		int zz,zzz;
    		cin>>zz>>zzz;
    		v[zz]=zzz;
    		sumi[zz]=1;
    		sita[zz]=zzz;
    		ue[zz]=zzz;
    	//	w[zz]=1;
    		if(i==1) r=zz,rr=zzz, saiki(zz,0);
    		else{
    //			cout<<zz<<" "<<guu[zz]<<" "<<zzz<<endl;
    			if(guu[zz]!= zzz%2){
    				cout<<"No"<<endl;
    				return 0;
    			}
    		}
    		
    	}
    	sai(r);
    	if(ok==false){
    		cout<<"No"<<endl;
    				return 0;
    	}
    	
    	for(int i=1;i<=n;i++){
    //		cout<<i<<" "<<sita[i]<<" "<<ue[i]<<endl;
    	}
    	
    	saikiz(r,0);
    	if(ok==false){
    		cout<<"No"<<endl;
    				return 0;
    	}
    	
    	cout<<"Yes"<<endl;
    	for(int i=1;i<=n;i++){
    		cout<<""<<ans[i]<<endl; 
    	}
    //	printf("%.10f\n",ans);
    	return 0;
    }

Measured memory_bytes: 24448