// Slower C++ solution:
#include <vector>

#include <queue>

#include <cmath>

#include <cstdio>

#include <cstring>

#include <iostream>



using namespace std;

const int N = 200000;



int n;

int ans[N];

vector <int> a[N];

priority_queue< pair<int,int> > q;



int main(void)

{

	scanf("%d", &n);

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

	{

		int x, y; scanf("%d %d", &x, &y);

		a[x].push_back(y);

		a[y].push_back(x);

	}

	memset(ans,-1,sizeof ans);

	int m; scanf("%d", &m);

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

	{

		int x, v; scanf("%d %d", &x, &v);

		ans[x] = v; q.push(make_pair(-v,x));

	}

	while (q.size())

	{

		int x = q.top().second;

		int v = -q.top().first;

		q.pop();

		for (int i=0;i<a[x].size();++i)

		{

			int y = a[x][i];

			if (ans[y] >= 0 and abs(ans[x]-ans[y]) ^ 1) {

				puts("No");

				return 0;

			}

			else if (ans[y] < 0) {

				ans[y] = v + 1;

				q.push(make_pair(-ans[y],y));

			}

		}

	}

	puts("Yes"); 

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

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

	return 0;

} 

// Faster C++ solution for the same problem (measured speedup: 2.0750851862782143x):
#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;

}