#include<bits/stdc++.h>
using namespace std;
struct _IO{_IO(){ios::sync_with_stdio(0);cin.tie(0);}}_io;
typedef long long ll; typedef long double db;
const int N = 5e5 + 5, M = 1e9 + 7;

vector<int> G[N];
int ans[N];

int main() {
  int n;
  cin >> n;
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  memset(ans, -1, sizeof ans);
  priority_queue<pair<int, int>> que;
  int k;
  cin >> k;
  for (int i = 0; i < k; i++) {
    int u, w;
    cin >> u >> w;
    ans[u] = w;
    que.push({-w, u});
  }
  while (que.size()) {
    int u;
    tie(ignore, u) = que.top();
    que.pop();
    for (int v : G[u]) {
      if (ans[v] > -1) {
        if (abs(ans[v] - ans[u]) != 1) {
          cout << "No";
          return 0;
        }
      } else {
        ans[v] = ans[u] + 1;
        que.push({-ans[v], v});
      }
    }
  }
  cout << "Yes\n";
  for (int i = 1; i <= n; i++) {
    cout << ans[i] << '\n';
  }
}
