#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 1e5 + 7;
const int BAD = -1e9;

int col[N];
bool have[N];
int par[N];
vector <int> good;
vector <int> g[N];

void dfs(int v, int pr) {
    par[v] = pr;
    have[v] = (col[v] != BAD);
    for (auto to : g[v]) {
        if (to != pr) {
            dfs(to, v);
            have[v] |= have[to];
        }
    }
}

void paint(int v, int cur) {
    col[v] = cur;
    for (int to : g[v]) {
        if (to != par[v]) {
            paint(to, cur + 1);
        }
    }
}

struct seg {
    int l, r;
    seg() {
        l = r = BAD;
    }
};

vector <seg> dp(N);

void solve(int v) {
    vector <seg> t;
    for (int to : g[v]) {
        if (to != par[v]) {
            solve(to);
            if (have[to] && dp[to].l == BAD) {
                cout << "No\n";
                exit(0);
            }
            if (have[to] && dp[to].l != BAD) {
                t.push_back(dp[to]);
            }
        }
    }
    if (col[v] != BAD) {
        dp[v].l = col[v];
        dp[v].r = col[v];
        return;
    }  
    if (t.empty()) {

    } else {
        int x = t[0].l % 2;
        bool bad = false;
        for (auto to : t) {
            if (to.l % 2 != x) {
                bad = true;
            }  
        }
        if (bad) {

        } else {
            int mn = 1e9, mx = -1e9;
            for (auto to : t) {
                mn = min(mn, to.r);
                mx = max(mx, to.l);
            }
            mn++;
            mx--;
            if (mn >= mx) {
                dp[v].l = mx;
                dp[v].r = mn;
            }
        }
    }
}

void flex(int v) {
    if (col[v] == BAD && have[v]) {
        int c = col[par[v]];
        if (c % 2 == dp[v].l % 2) {
            cout << "No\n";
            exit(0);
        }
        if (c + 1 > dp[v].r || c + 1 < dp[v].l) {
            if (c - 1 > dp[v].r || c - 1 < dp[v].l) {
                cout << "No\n";
                exit(0);
            }
            col[v] = c - 1;
        } else {
            col[v] = c + 1;
        }
    }
    for (auto to : g[v]) {
        if (to != par[v]) {
            flex(to);
        }
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    for (int i = 0; i < N; i++) {
        col[i] = BAD;
    }
    int n;
    cin >> n;
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    int k;
    cin >> k;
    for (int i = 0; i < k; i++) {
        int v, c;
        cin >> v >> c;
        v--;
        col[v] = c;
    }
    dfs(0, -1);
    solve(0);
    if (dp[0].l == BAD) {
        cout << "No" << '\n';
        return 0;
    }
    col[0] = dp[0].l;
    flex(0);
    for (int i = 1; i < n; i++) {
        if (col[par[i]] != BAD && !have[i] && col[i] == BAD) {
            paint(i, col[par[i]] + 1);
        }
    }
    for (int i = 0; i < n; i++) {
        for (auto to : g[i]) {
            if (col[to] == BAD || abs(col[i] - col[to]) != 1) {
                cout << "No\n";
                return 0;
            }
        }
    }
    cout << "Yes\n";
    for (int i = 0; i < n; i++) {
        cout << col[i] << '\n';
    }
    return 0;
}

Measured memory_bytes: 15872