#include <cassert>
#include "limits.h"
#include <limits>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <memory>
#include <utility>
 
#define rep(i, a, b) for (long long (i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

void debug_out(){std::cerr<<std::endl;}

template<typename H,typename... T>
void debug_out(H head,T... tail){
  std::cerr<<" "<<head;
  debug_out(tail...);
}

 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
long long pow_mod(long long a, long long b, long long mod=-1) {
  if ((a == 0)||(mod!=-1&&a%mod==0)) {
    return 0;
  }
 
  long long x = 1;
 
  while (b > 0) {
    if (b & 1) {
      x = (mod!=-1)?(x * a) % mod:x*a;
    }
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}
 
const long long MOD = 998244353;
// const long long MOD = 1e9 + 7;

using ll = long long;
using P = std::pair<long long,long long>;

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);

  ll n;
  std::cin>>n;

  std::vector<std::vector<ll>> graph(n);

  rep(i,0,n-1){
    ll a,b;
    std::cin>>a>>b;
    a--;b--;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }

  std::vector<ll> num(n,-1);

  ll k;
  std::cin>>k;

  ll temp=-1;

  rep(i,0,k){
    ll v,p;
    std::cin>>v>>p;
    v--;
    num[v]=p;
    temp=v;
  }

  {
    bool isok=true;
    auto f=[&](auto f,ll now,ll par,ll parity)->void{
      for(ll next:graph[now]){
        if(next!=par){
          if(num[next]!=-1&&(num[next]%2)==parity){
            isok=false;
            return;
          }
          f(f,next,now,(parity+1)%2);
        }
      }
    };
    f(f,temp,-1,num[temp]%2);
    if(!isok){
      std::cout<<"No\n";
      return 0;
    }
  }

  std::vector<P> seg(n,{-MOD,MOD});

  rep(i,0,n){
    if(num[i]!=-1)seg[i]={num[i],num[i]};
  }

  {
    bool isok=true;
    auto f=[&](auto f,ll now,ll par)->void{
      for(ll next:graph[now]){
        if(next!=par){
          f(f,next,now);
          chmax(seg[now].first,seg[next].first-1);
          chmin(seg[now].second,seg[next].second+1);
        }
      }
      if(seg[now].first>seg[now].second)isok=false;
    };
    f(f,temp,-1);
    if(!isok){
      std::cout<<"No\n";
      return 0;
    }
  }

  {
    auto f=[&](auto f,ll now,ll par)->void{
      for(ll next:graph[now]){
        if(next!=par){
          if(seg[next].first<=num[now]+1&&num[now]+1<=seg[next].second){
            num[next]=num[now]+1;
          }else{
            num[next]=num[now]-1;
          }
          f(f,next,now);
        }
      }
    };
    f(f,temp,-1);
  }

  std::cout<<"Yes\n";

  rep(i,0,n)std::cout<<num[i]<<"\n";

  return 0;
}

Measured memory_bytes: 13312