// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



struct Node{

	int x, id;

	Node(){}

	Node(int _x, int _id){x = _x, id = _id;}

	bool operator < (const Node &A) const{

		return id > A.id;

	}

};



vector <int> from[100010];

priority_queue <Node> q;

int id[100010];



int main(){

	int n;

	scanf("%d", &n);

	for (int i = 1; i < n; i++){

		int u, v;

		scanf("%d%d", &u, &v);

		from[u].push_back(v);

		from[v].push_back(u);

	}

	int m;

	scanf("%d", &m);

	memset(id, -1, sizeof(id));

	for (int i = 0; i < m; i++){

		int a, b;

		scanf("%d%d", &a, &b);

		id[a] = b;

		q.push(Node(a, b));

	}

	while (!q.empty()){

		Node t = q.top(); q.pop();

		int u = t.x;

		for (int i = 0; i < from[u].size(); i++){

			int v = from[u][i];

			if (id[v] == -1) id[v] = t.id + 1, q.push(Node(v, t.id + 1));

		}

	}

	bool pd = 0;

	for (int i = 1; i <= n; i++){

		for (int j = 0; j < from[i].size(); j++){

			int v = from[i][j];

			if (abs(id[i] - id[v]) != 1){

				pd = 1;

				break;

			}

		}

		if (pd) break;

	}

	if (pd){

		printf("No\n");

		return 0;

	}

	printf("Yes\n");

	for (int i = 1; i <= n; i++){

		printf("%d\n", id[i]);

	}

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.1037249050056626x):
#include<bits/stdc++.h>

#define ll long long

#define endl '\n'

#define fi first

#define se second

#define ls(a) tree[a].l

#define rs(a) tree[a].r

#define lz(a)  tree[a].lz

#define sum(a) tree[a].sum

#define rep(i,l,r) for(int i=l;i<=r;i++)

#define per(i,r,l) for(int i=r;i>=l;i--)

#define mid l+r>>1

#define lson l,mid,ls(p)

#define rson (mid)+1,r,rs(p)

const int MX=1e5+7;

const int N=1e9+1;

const int mod=998244353;

const double pi=3.1415926535897932384;

double isp=1e-13;

using namespace std;

ll qpow(ll a,ll b,ll MOD=mod){for(ll ans=1;;a=a*a%MOD,b>>=1){if(b&1)ans=ans*a%MOD;if(!b)return ans;}}

ll inv(ll a,ll MOD=mod){return qpow(a,MOD-2,MOD);}//要求MOD为质数

ll exgcd(ll a,ll b,ll &x,ll &y){if(b==0){x=1,y=0;return a;}ll ret=exgcd(b,a%b,y,x);y-=a/b*x;return ret;}

ll getInv(int a,int mod){ll x,y;ll d=exgcd(a,mod,x,y);return d==1?(x%mod+mod)%mod:-1;}//求a在mod下的逆元，不存在逆元返回-1，不要求MOD为质数

ll add(ll a,ll b){ll ans=(a+b)%mod;return ans>=0?ans:ans+mod;}

void  mul(ll &a,ll b){a=a%mod*(b%mod)%mod; }

vector<int>G[MX];

int a[MX];

int main()

{

  ios::sync_with_stdio(0),cin.tie(0);

  int n;

  cin>>n;

  rep(i,1,n)a[i]=mod;

  for(int i=1;i<n;i++)

  {

      int x,y;

      cin>>x>>y;

      G[x].push_back(y);

      G[y].push_back(x);

  }

  priority_queue<pair<int,int>>q;

  int k;

  cin>>k;

  rep(i,1,k)

  {

      int x,val;

      cin>>x>>val;

      a[x]=val;

      q.push({-val,x});

  }

  if(q.empty())

  {

      q.push({0,1});

  }

  int tmp=0;

  while(!q.empty())

  {

      auto x=q.top();

      q.pop();

      int val=-x.fi;

  //    cout<<val<<" "<<x.se<<endl;

      for(int y:G[x.se])

      {

//          cout<<y<<" a="<<a[y]<<endl;



          if(a[y]<mod)

          {

              if(abs(a[y]-val)!=1)

              {

                  tmp++;

                  break;

              }

          }

          else

          {

              a[y]=val+1;

              q.push({-val-1,y});

          }



    //      cout<<y<<" a2="<<a[y]<<endl;

      }

      if(tmp)break;

  }

  if(tmp){

    cout<<"No"<<endl;

    return 0;

  }

  cout<<"Yes"<<endl;

  rep(i,1,n)cout<<a[i]<<endl;

}