#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

template <typename T>
vector<T> dijkstra(int s, vector<vector<pair<int, T>>> &G) {
    const T inf = numeric_limits<T>::max();
    using P     = pair<T, int>;
    int n       = G.size();
    vector<T> d(n, inf);
    priority_queue<P, vector<P>, greater<P>> q;
    d[s] = 0;
    q.emplace(d[s], s);
    while (!q.empty()) {
        P p = q.top();
        q.pop();
        int v = p.second;
        if (d[v] < p.first)
            continue;
        for (auto &e : G[v]) {
            int u = e.first;
            T c   = e.second;
            if (d[u] > d[v] + c) {
                d[u] = d[v] + c;
                q.emplace(d[u], u);
            }
        }
    }
    return d;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<vector<pair<int, lint>>> edges(n);
    for (int i = 0; i < n - 1; ++i) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        edges[u].emplace_back(v, 1);
        edges[v].emplace_back(u, 1);
    }
    int k;
    cin >> k;
    vector<lint> p(n, -inf);
    vector<lint> vs(n), ps(n);
    for (int i = 0; i < k; ++i) {
        cin >> vs[i] >> ps[i];
        vs[i]--;
        p[vs[i]] = ps[i];
    }
    auto dist = dijkstra(vs[0], edges);
    for (int i = 1; i < k; ++i) {
        if (abs(ps[i] - ps[0]) % 2 != dist[vs[i]] % 2) {
            cout << "No"
                 << "\n";
            return 0;
        }
    }
    vector<lint> mini(n, -inf);
    vector<lint> maxi(n, inf);
    bool ok                        = true;
    function<void(int, int)> dfsup = [&](int c, int pa) {
        if (p[c] != -inf) {
            maxi[c] = mini[c] = p[c];
        }
        for (auto &w : edges[c]) {
            int v = w.first;
            if (v == pa)
                continue;
            dfsup(v, c);
            if (mini[v] != -inf)
                chmax(mini[c], mini[v] - 1);
            if (maxi[v] != inf)
                chmin(maxi[c], maxi[v] + 1);
        }
        if (p[c] != -inf) {
            if (mini[c] > p[c] || maxi[c] < p[c]) {
                ok = false;
            }
        }
    };
    dfsup(0, -1);
    function<void(int, int)> dfsdn = [&](int c, int pa) {
        if (p[c] != -inf) {
            if (mini[c] > p[c] || maxi[c] < p[c]) {
                ok = false;
            }
        }
        for (auto &w : edges[c]) {
            int v = w.first;
            if (v == pa)
                continue;
            if (mini[c] != -inf)
                chmax(mini[v], mini[c] - 1);
            if (maxi[c] != inf)
                chmin(maxi[v], maxi[c] + 1);
            dfsdn(v, c);
        }
    };
    dfsdn(0, -1);
    for (int i = 0; i < n; ++i) {
        if (maxi[i] >= mini[i]) {
            p[i] = mini[i];
        } else {
            ok = false;
        }
    }
    if (!ok) {
        cout << "No"
             << "\n";
    } else {
        cout << "Yes"
             << "\n";
        for (int i = 0; i < n; ++i) {
            cout << p[i] << "\n";
        }
    }
    return 0;
}

Measured memory_bytes: 22016