#include <bits/stdc++.h>
using namespace std;

const int MAXN = 100005;

set <pair <int, int> > ms;
int a[MAXN];
vector <int> g[MAXN];
int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n-1; i++)
    {
        int u, v;
        cin >> u >> v;
        g[v].push_back(u);
        g[u].push_back(v);
    }
    for (int i = 1; i <=n; i++) a[i] = -1;
    int m;
    cin >> m;
    for (int i = 0; i < m; i++)
    {
        int u, w;
        cin >> u >> w;
        a[u] = w;
        ms.insert({w, u});
    }

    while(!ms.empty())
    {
        int v = ms.begin()->second;
     //   cout << v << " " << a[v] << endl;
        ms.erase(ms.begin());
        for (int i = 0; i < g[v].size(); i++)
        {
            int to = g[v][i];
            if (a[to] == -1)
            {
                a[to] = a[v] + 1;
                ms.insert({a[to], to});
            }
            else if (max(a[to] - a[v], a[v] - a[to]) != 1)
            {
                cout << "No";
                return 0;
            }
        }
    }

    cout << "Yes" << endl;
    for (int i = 1; i <= n; i++)
    {
        cout << a[i] << endl;
    }

    return 0;
}
