#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define REVERSE(x) reverse((x).begin(), (x).end())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << '\n'

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-10;

constexpr int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
constexpr int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

template<typename T>
bool chmax(T& a, T b){
    if(a < b){
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool chmin(T& a, T b){
    if(b < a){
        a = b;
        return true;
    }
    return false;
}

vector< vector<int> > g;
vector<int> ma;
vector<int> mi;
vector<int> eo;
vector<int> ans;

void init(int n){
    g.assign(n, vector<int>(0));
    ma.assign(n, IINF);
    mi.assign(n, -IINF);
    eo.assign(n, -1);
    ans.assign(n, -1);
    return;
}

void dfs1(int v, int c){
    eo[v] = c;

    for(auto to : g[v]){
        if(eo[to] < 0){
            dfs1(to, c ^ 1);
        }
    }

    return;
}

P dfs2(int v, int prev){
    P res = make_pair(ma[v], mi[v]);

    for(auto to : g[v]){
        if(to == prev){
            continue;
        }

        P tmp = dfs2(to, v);
        chmin(res.first, tmp.first + 1);
        chmax(res.second, tmp.second - 1);
    }

    ma[v] = res.first;
    mi[v] = res.second;

    if(res.first < res.second || ans[v] != -1 && (res.first < ans[v] || ans[v] < res.second)){
        return make_pair(-IINF, IINF);
    }

    return res;
}

void dfs3(int v, int prev, int val){
    if(ans[v] == -1){
        ans[v] = val < ma[v] ? val + 1 : val - 1;
    }

    for(auto to : g[v]){
        if(to == prev){
            continue;
        }

        dfs3(to, v, ans[v]);
    }

    return;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int n;
    cin >> n;

    init(n);

    rep(i, n - 1){
        int a, b;
        cin >> a >> b;
        g[--a].emplace_back(--b);
        g[b].emplace_back(a);
    }

    int k;
    cin >> k;

    int s, c;

    rep(i, k){
        int v, p;
        cin >> v >> p;
        ans[--v] = p;
        ma[v] = p;
        mi[v] = p;
        s = v;
        c = p & 1;
    }

    dfs1(s, c);

    rep(i, n){
        if(ma[i] == IINF){
            continue;
        }

        if((eo[i] & 1) ^ (ma[i] & 1)){
            cout << "No" << endl;
            return 0;
        }
    }

    dfs2(0, -1);

    rep(i, n){
        if(ma[i] < mi[i]){
            cout << "No" << endl;
            return 0;
        }
    }

    dfs3(0, -1, ma[0] - 1);

    cout << "Yes" << '\n';
    rep(i, n){
        cout << ans[i] << '\n';
    }

    cout << flush;

    return 0;
}

Measured memory_bytes: 15744