#include<bits/stdc++.h>

using namespace std;
vector<int> G[123456];
int d[123456];
int main()
{
    int n;
    ios::sync_with_stdio(0);
    cin >> n ;
    for (int i=0;i<n-1;i++)
    {
        int x,y;
        cin >> x>> y;
        --x,--y;
        G[x].push_back(y);
        G[y].push_back(x);
    }
    int k;
    cin >> k ;
    priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;
    memset(d,-1,sizeof(d));
    while(k--)
    {
        int x,y;
        cin >> x >>y;
        d[x-1]=y;
        pq.push({y,x-1});
    }
    while(!pq.empty())
    {
        pair<int,int> p=pq.top();pq.pop();
        int u=p.second;
        for (int i=0;i<G[u].size();i++)
        {
            int v=G[u][i];
            if (d[v]==-1)
            {
                d[v]=d[u]+1;
                pq.push({d[v],v});
            }
        }
    }
    for (int u=0;u<n;u++)
    {
        for (int i=0;i<G[u].size();i++)
        {
            int v=G[u][i];
            if (abs(d[u]-d[v])!=1)
            {
                cout << "No" << endl;
                exit(0);
            }
        }
    }
    cout << "Yes" << endl;
    for (int i=0;i<n;i++) cout << d[i] << endl;
    return 0;
}
