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



using namespace std;



const int N = 1e5 + 5;

const int inf = 0x3f3f3f3f;



vector <int> g[N];

int n, k, dist[N];

priority_queue <pair <int, int>, vector <pair <int, int> >, greater <pair <int, int> > > pq;



void input(){

    scanf("%d", &n);

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

        int u, v;

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

        g[u].push_back(v);

        g[v].push_back(u);

    }



    scanf("%d", &k);

    memset(dist, 0x3f, sizeof(dist));

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

        int u, x;

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

        dist[u] = x;

        pq.push(make_pair(dist[u], u));

    }

}



void dijkstra(){

    while (!pq.empty()) {

        int d = pq.top().first;

        int u = pq.top().second;

        pq.pop();



        for (int v: g[u]) {

            if (dist[v] == inf) {

                dist[v] = dist[u] + 1;

                pq.push(make_pair(dist[v], v));

            }

            else if (abs(dist[v] - dist[u]) != 1) {

                printf("No");

                return;

            }

        }

    }



    puts("Yes");

    for (int i = 1; i <= n; i++) printf("%d\n", dist[i]);

}



void solve(){

    dijkstra();

}



signed main(){

    input();

    solve();

    return 0;

}


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

}