#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}

#define MAX_N 200005
vector<int> pre_G[MAX_N];
vector<int> G[MAX_N];
int par[MAX_N];
int flag_netsukigi[MAX_N];
void make_netsukigi(int r){
    queue<int> que;
    que.push(r);
    flag_netsukigi[r] = 1;
    par[r] = -1;

    while(que.size() > 0){
        int x = que.front();
        que.pop();
        flag_netsukigi[x] = 1;
        rep(i,pre_G[x].size()){
            if(flag_netsukigi[pre_G[x][i]] == 0){
                par[pre_G[x][i]] = x;
                G[x].push_back(pre_G[x][i]);
                que.push(pre_G[x][i]);
            }
        }
    }
}

int is_free[MAX_N] = {};
int l[MAX_N] = {};
int r[MAX_N] = {};
int ans[MAX_N] = {};

void dfs(int x){
    if(G[x].size() == 0){
        ; // 葉
    }else{
        rep(i,G[x].size()){
            if(is_free[G[x][i]] == 0){
                ans[G[x][i]] = ans[x] - 1;
                dfs(G[x][i]);
            }else{
                l[G[x][i]] = max(l[G[x][i]], ans[x] - 1);
                r[G[x][i]] = min(r[G[x][i]], ans[x] + 1);
                ans[G[x][i]] = l[G[x][i]];
                dfs(G[x][i]);
            }
        }
    }
}

int main() {
    int n;
    cin >> n;

    
    rep(i,n-1){
        int a, b;
        scanf("%d%d", &a, &b);
        a--; b--; // 0-indexにするため.
        pre_G[a].push_back(b);
        pre_G[b].push_back(a);
    }

    make_netsukigi(0);


    
    int count_sons[MAX_N] = {};
    queue<int> que;
    rep(i,n){
        if(G[i].size() == 0){ // 葉かどうか.
            que.push(i);
        }
    }

    

    int k;
    cin >> k;
    rep(i,k){
        int v, p;
        scanf("%d%d", &v, &p);
        v--; // 0-indexにするため.
        if(p%2==1){
            is_free[v] = 1;
        }else{
            is_free[v] = 2;
        }
        l[v] = p;
        r[v] = p;
    }

    // Yes No 判定
    while(que.size() > 0){
        int x = que.front();
        //cout << x << ' ';
        que.pop();
        if(par[x] == -1)continue;
        if(count_sons[x] < G[x].size())continue;
        count_sons[par[x]]++;
        que.push(par[x]);
        if(is_free[x] != 0){
            if(is_free[par[x]] == 0){
                if(is_free[x] == 1){
                    is_free[par[x]] = 2;
                }else{
                    is_free[par[x]] = 1;
                }
                l[par[x]] = l[x] - 1;
                r[par[x]] = r[x] + 1;
            }else{
                if(is_free[x] == is_free[par[x]]){
                    cout << "No" << endl;
                    return 0;
                }
                if(l[x] % 2 == l[par[x]] % 2)l[par[x]]++;
                if(r[x] % 2 == r[par[x]] % 2)r[par[x]]--;
                if(r[x] + 1 < l[par[x]] || r[par[x]] + 1 < l[x]){
                    cout << "No" << endl;
                    return 0;
                }
                l[par[x]] = max(l[par[x]], l[x] - 1);
                r[par[x]] = min(r[par[x]], r[x] + 1);
                if(r[par[x]] < l[par[x]]){
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }

    // 逆伝播
    ans[0] = l[0];
    dfs(0);
    /*
    cout << endl;
    rep(i,n){
        cout << "i = " << i << "is_free" << is_free[i] << " : ";
        rep(j,G[i].size()){
            cout << G[i][j] << ' ';
        }
        cout << endl;
    }
    cout << endl;
    */
    cout << "Yes" << endl;
    rep(i,n){
        printf("%d\n", ans[i]);
    }

    return 0;
}
 
 


Measured memory_bytes: 25856