#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>
#include <queue>

using namespace std;

int main(){

    const int INF = 10000000;

    int N;
    cin >> N;
    vector<vector<int>> E(N);
    vector<int> cnt(N, 0);
    int a, b;
    for(int i = 0; i < N - 1; i++){
        cin >> a >> b;
        E[a - 1].push_back(b - 1);
        E[b - 1].push_back(a - 1);
        cnt[a - 1]++;
        cnt[b - 1]++;
    }

    vector<int> parity(N, 0);
    pair<int, int> infPair = make_pair(INF, INF);
    vector<pair<int, int>> P(N, infPair);
    int K;
    cin >> K;
    int v, p;
    for(int i = 0; i < K; i++){
        cin >> v >> p;
        if(p % 2 == 0){
            parity[v - 1] = 1;
        }
        else{
            parity[v - 1] = -1;
        }
        P[v - 1] = make_pair(p, p);
    }
    
    vector<bool> checkDfs(N, false);
    queue<int> q1;
    q1.push(v - 1);
    checkDfs[v - 1] = true;
    while(!q1.empty()){
        int temp = q1.front();
        q1.pop();
        int tempParity = parity[temp];

        for(auto node: E[temp]){
            if(checkDfs[node]){
                continue;
            }

            if(parity[node] == 0){
                parity[node] = (tempParity * -1);
            }
            else{
                if(parity[node] == tempParity){
                    cout << "No" << endl;
                    exit(0);
                }
            }

            q1.push(node);
            checkDfs[node] = true;
        }
    }

    vector<bool> check(N, false);
    queue<int> q;
    for(int i = 0; i < N; i++){
        if(cnt[i] == 1){
            cnt[i]--;
            q.push(i);
        }
    }

    int lastNode = 0;
    while(!q.empty()){
        int temp = q.front();
        lastNode = temp;
        q.pop();
        auto tempRange = P[temp];
        check[temp] = true;

        for(auto node: E[temp]){
            if(check[node]){
                continue;
            }

            auto nodeRange = P[node];
            if(nodeRange == infPair && tempRange != infPair){
                P[node] = make_pair(tempRange.first - 1, tempRange.second + 1);
            }
            else if(tempRange != infPair){
                int left = max(nodeRange.first, tempRange.first - 1);
                int right = min(nodeRange.second, tempRange.second + 1);
                if(left > right){
                    cout << "No" << endl;
                    exit(0);
                }
                P[node] = make_pair(left, right);
            }

            cnt[node]--;
            if(cnt[node] == 1){
                q.push(node);
            }
        }
    }

    queue<int> q2;
    vector<bool> checkAns(N, false);
    vector<int> ans(N);
    q2.push(lastNode);
    checkAns[lastNode] = true;

    while(!q2.empty()){
        int temp = q2.front();
        q2.pop();
        auto tempRange = P[temp];
        ans[temp] = tempRange.first;

        for(auto node: E[temp]){
            if(checkAns[node]){
                continue;
            }
            auto nodeRange = P[node];
            if(nodeRange == infPair){
                P[node] = make_pair(tempRange.first - 1, tempRange.first + 1);
            }
            else{
                int f = tempRange.first;
                if(nodeRange.first <= f - 1 && f - 1 <= nodeRange.second){
                    P[node] = make_pair(f - 1, f - 1);
                }
                else if(nodeRange.first <= f + 1 && f + 1 <= nodeRange.second){
                    P[node] = make_pair(f + 1, f + 1);
                }
                else{
                    cout << "No" << endl;
                    exit(0);
                }
            }
            q2.push(node);
            checkAns[node] = true;
        }
    }

    cout << "Yes" << endl;
    for(int i = 0; i < N; i++){
        cout << ans[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 10112