#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=1e5+5;
vector< ll > adj[N];
ll n,k,ans[N];
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cin>>n;
    for(ll i=1;i<=n;i++)ans[i]=-N;
    for(ll i=1,u,v;i<=n-1;i++)cin>>u>>v,adj[u].push_back(v),adj[v].push_back(u);
    priority_queue< pair<ll,ll> >pq;
    cin>>k;
    for(ll i=0,u,w;i<k;i++)cin>>u>>w,ans[u]=w,pq.push({w,u});
    while(!pq.empty()){
        ll w=pq.top().first,u=pq.top().second;
        pq.pop();
        for(auto &v:adj[u]){
            if(ans[v]==ans[u]+1 || ans[v]==ans[u]-1)continue;
            if(ans[v]!=-N)return cout<<"No" , 0;
            ans[v]=ans[u]-1;
            pq.push({ans[v],v});
        }
    }
    cout<<"Yes\n";
    for(ll i=1;i<=n;i++)cout<<ans[i]<<"\n";
}