#include <bits/stdc++.h>
 
using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
// get decimal part of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
long long mod = 1000000007;

// 32 mil = ~1 sec 
long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}
 
/*string sentence = And I feel fine...;
    istringstream iss(sentence);
*/  
 
double eps = .000000001;
int nums[100001];
vector<int> graph[100001];
pair<int, int> ahead[100001];
int full[100001];
int marked = 0;
bool imp = false;
vector<pair<int, int> > edges;
pair<int, int> dfs(int node, int par){
    if (imp){
        return {-1, -1};
    }
    
    int maxl = -1000000000;
    int minr = 1000000000;
    for (int i : graph[node]){
        if (i == par){
            continue;
        }
        edges.emplace_back(node, i);
        pair<int, int> p = dfs(i, node);
        maxl = max(maxl, p.first);
        minr = min(minr, p.second);
        if (node == 3){
            //cout << p.first << " " << p.second<< endl;
        }
    }
    
    if (nums[node] != -1){
        ahead[node] = {nums[node], nums[node]};
        return {nums[node]-1, nums[node]+1};
    }
    if (graph[node].size() == 1){
        ahead[node] = {-1000000000, 1000000000};
        return {-1000000000, 1000000000};
    }
   
    ahead[node] = {maxl, minr};
    return {maxl-1, minr+1};
}
int res[100001];
bool inrange(int l, int r, int num){
    if (num < l || num > r){
        return false;
    }
    return true;
}
bool bad = false;
void mark(int node, int par, int last){
    int l = ahead[node].first;
    int r = ahead[node].second;
    if (inrange(l, r, last+1)){
        res[node] = last+1;
    }else if (inrange(l, r, last-1)){
        res[node] = last-1;
    }else{
        bad = true;
        return;
    }
    for (int j : graph[node]){
        if (j == par){
            continue;
        }
        mark(j, node, res[node]);
    }
}
int main ()
{
  prep();
  int n;
  cin >> n;
  
  for (int i=0; i<n-1; i++){
      int a, b;
      cin >> a >> b;
      graph[a].push_back(b);
      graph[b].push_back(a);
  }
  int k;
  cin >> k;
  memset(nums, -1, sizeof(int)*(n+1));
  
  for (int i=0; i<k; i++){
      int v, m;
      cin >> v >> m;
      nums[v] = m;
      marked = v;
  }
  dfs(marked, -1);

  
  for (pair<int, int> p : edges){
      int a = p.first;
      int b = p.second;
      int myl = ahead[a].first;
      int myr = ahead[a].second;
      int theirl = ahead[b].first;
      int theirr = ahead[b].second;
      if (myl < theirl-1){
          myl = theirl-1;
      }else if (theirl < myl-1){
          theirl = myl-1;
      }
      if (myr > theirr+1){
          myr = theirr+1;
      }else if (theirr > myr+1){
          theirr = myr+1;
      }
      ahead[a] = {myl, myr};
      ahead[b] = {theirl, theirr};
  }
  for (int i=1; i<=n; i++){
      if (ahead[i].first > ahead[i].second){
          cout << "No";
          return 0;
      }
      //cout << ahead[i].first << " " << ahead[i].second << endl;
  }
  
  
  mark(marked, -1, nums[marked]-1);
  if (bad){
      cout << "No";
      return 0;
  }
  cout << "Yes\n";
  for (int i=1; i<=n; i++){
      cout << res[i] << '\n';
  }
  return 0; 
}


Measured memory_bytes: 16756