#include <bits/stdc++.h>
#define show(x) cerr << #x << " = " << x << endl
using namespace std;
using P  = pair<int, int>;
using PP = pair<bool, P>;
struct Graph
{
    Graph(const int v)
        : V{ v }, edge(v), rev_edge(v) {}
    void addEdge(const int from, const int to)
    {
        edge[from].push_back(to);
        rev_edge[to].push_back(from);
    }
    const int V;
    vector<vector<int>> edge;
    vector<vector<int>> rev_edge;
};

inline bool ng(const PP& p)
{
    return (not p.first) and (((((p.second.first + p.second.first) % 2) + 2) % 2 == 1) or p.second.first > p.second.second);
}
inline PP merge(const PP& p1, const PP& p2)
{
    if (p1.first) {
        return p2;
    } else if (p2.first) {
        return p1;
    } else {
        if ((((p1.second.first + p2.second.first) % 2) + 2) % 2 == 0) {
            return { false, { max(p1.second.first, p2.second.first), min(p1.second.second, p2.second.second) } };
        } else {
            return { false, { 0, -2 } };
        }
    }
}

inline PP next(const PP& p) { return (ng(p) ? PP{ false, { 0, -2 } } : PP{ p.first, { p.second.first - 1, p.second.second + 1 } }); }
template <typename T, typename A>
ostream& operator<<(ostream& os, const vector<T, A>& v)
{
    os << "[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]";
    return os;
}
template <typename S, typename T>
ostream& operator<<(ostream& os, const pair<S, T>& p)
{
    os << "<" << p.first << "," << p.second
       << ">";
    return os;
}

void dfs(const Graph& g, const int s, vector<bool>& used, vector<PP>& cand, const vector<int>& node)
{
    used[s] = true;
    PP ans  = { true, { 0, 0 } };
    if (node[s] != -1) {
        ans = merge(ans, { false, { node[s], node[s] } });
    }
    for (const int to : g.edge[s]) {
        if (not used[to]) {
            dfs(g, to, used, cand, node);
            if (not cand[to].first) {
                ans = merge(ans, next(cand[to]));
                if (ng(ans)) {
                    ans = { false, { 0, -2 } };
                }
            }
        }
    }
    cand[s] = ans;
}

void dfs(const Graph& g, const int s, const int par, vector<bool>& used, const vector<PP>& cand, vector<int>& node)
{
    used[s]        = true;
    const auto tmp = merge(cand[s], { false, { par - 1, par + 1 } });
    node[s]        = tmp.second.first;
    for (const int to : g.edge[s]) {
        if (not used[to]) {
            dfs(g, to, node[s], used, cand, node);
        }
    }
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    Graph g(N);
    vector<int> node(N, -1);
    for (int i = 0; i < N - 1; i++) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        g.addEdge(u, v);
        g.addEdge(v, u);
    }
    int K;
    cin >> K;
    for (int i = 0; i < K; i++) {
        int v, p;
        cin >> v >> p;
        v--;
        node[v] = p;
    }
    vector<PP> cand(N);
    vector<bool> used(N, false);
    dfs(g, 0, used, cand, node);
    if (ng(cand[0])) {
        cout << "No" << endl;
        return 0;
    } else if (cand[0].first) {
        node[0] = 0;
        cand[0] = { false, { 0, 0 } };
    } else {
        node[0] = cand[0].second.first;
        cand[0] = { false, { cand[0].second.first, cand[0].second.first } };
    }
    fill(used.begin(), used.end(), false);
    dfs(g, 0, cand[0].second.first + 1, used, cand, node);
    cout << "Yes" << endl;
    for (int i = 0; i < N; i++) {
        cout << node[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 24448