#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int parents[100500];
vector<int> children[100500];
vector<int> pathes[100500];
int n;
int p[100050];
int maxi[100050];
int mini[100050];
int checker[100050];
int ans[100050];

void dfs(int from){
    //cout << "1 " << from << endl;
    for(int i = 0; i < pathes[from].size(); i++){
        int to = pathes[from][i];
        if(to == parents[from]) continue;
        parents[to] = from;
        children[from].push_back(to);
        dfs(to);
    }
}

void dfs2(int from){
    //cout << "2 " << from << endl;
    if(children[from].empty()){
        if(p[from] > -1){
            maxi[from] = p[from];
            mini[from] = p[from];
            checker[from] = p[from] % 2;
            return;
        }
        maxi[from] = INF;
        mini[from] = -INF;
        checker[from] = 2;
        return;
    }
    checker[from] = 2;
    maxi[from] = INF;
    mini[from] = -INF;
    for(int i = 0; i < children[from].size(); i++){
        int to = children[from][i];
        dfs2(to);
        if(checker[to] == -1){
            checker[from] = -1;
            return;
        } 
        maxi[from] = min(maxi[from], maxi[to] + 1);
        mini[from] = max(mini[from], mini[to] - 1);
        if(checker[to] == 2) continue;
        if(checker[from] == 2){
            checker[from] = 1 - checker[to];
            continue;
        }
        if(checker[from] == checker[to]){
            checker[from] = -1;
            return;
        }
    }
    if(p[from] > -1){
        maxi[from] = min(p[from], maxi[from]);
        mini[from] = max(p[from], mini[from]);
    }
    if(maxi[from] < mini[from]){
        checker[from] = -1;
        return;
    }
    if(checker[from] == 2) return;
    if(maxi[from] % 2 != checker[from]) maxi[from]--;
    if(mini[from] % 2 != checker[from]) mini[from]++;
    if(maxi[from] < mini[from]){
        checker[from] = -1;
    }
    return;
}

void dfs3(int from){
    if(from == 1){
        ans[from] = maxi[from];
        for(int i = 0; i < children[from].size(); i++){
            dfs3(children[from][i]);
        }
        return;
    }
    int value = ans[parents[from]];
    if(maxi[from] >= value + 1){
        ans[from] = value + 1;
    } else {
        ans[from] = value - 1;
    }
    for(int i = 0; i < children[from].size(); i++){
        dfs3(children[from][i]);
    }
    return;
}

int main() {
    //cout.precision(10);
    cin >> n;
    for(int i = 1; i < n; i++){
        int a, b;
        cin >> a >> b;
        pathes[a].push_back(b);
        pathes[b].push_back(a);
        p[i] = -1;
    }
    p[n] = -1;
    int k;
    cin >> k;
    for(int i = 1; i <= k; i++){
        int v, P;
        cin >> v >> P;
        p[v] = P;
    }
    parents[1] = 1;
    dfs(1);
    dfs2(1);
    for(int i = 1; i <= n; i++){
        //cout << i << " " << maxi[i] << " " << mini[i] << " " << checker[i] << endl;
    }
    if(checker[1] == -1){
        cout << "No" << endl;
        return 0;
    }
    dfs3(1);
    cout << "Yes" << endl;
    for(int i = 1; i <= n; i++){
        cout << ans[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 22016