#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <cstring>
#include <math.h>
#include <time.h>
#define MAXN 111111
#define Inf 1000000000
using namespace std;


pair<int,int> range[MAXN+1];
vector<int> edges[MAXN+1];
vector<int> unset_edges[MAXN+1];
bool isset[MAXN+1];

bool change;
map<pair<int,pair<int,pair<int,int> > >,bool> done;
bool dfs(int par, int u, pair<int,int> rg) {
    
    
    rg.first--;
    rg.second++;
    
    pair<int,int> prev_range = range[u];
    range[u].first = max(range[u].first, rg.first);
    range[u].second = min(range[u].second, rg.second);
    
    if (range[u] != prev_range)
        change = true;
    
    if (range[u].first > range[u].second)
        return false;
    

    if (isset[u])
        return true;
    
    
    if (done.find(make_pair(u,make_pair(u,range[u]))) != done.end())
        return done[make_pair(u,make_pair(u,range[u]))];
    
    bool retval = true;
    for(int j=0;j<unset_edges[u].size();j++) {
        int v = unset_edges[u][j];
        if (v == par)
            continue;
        if (!dfs(u,v,range[u])) {
            retval=false;
            break;
        }
    }
    done[make_pair(u,make_pair(u,range[u]))]=retval;
    return retval;
    
}

int answer[MAXN+1];

bool dfs2(int par, int u,int par_val) {
    
    // either par_val-1 or par_val+1.
    
    bool can = false;
    int val;
    for(int t=par_val-1;t<=par_val+1;t+=2) {
        if (range[u].first <= t && range[u].second >= t) {
            can=true;
            val=t;
            break;
        }
    }
    
    if (!can)
        return false;
    
    answer[u]=val;
    for(int j=0;j<edges[u].size();j++) {
        int v=edges[u][j];
        if (v == par)
            continue;
        if (!dfs2(u,v,val))
            return false;
    }
    return true;
    
}

int main() {
    int N;
    cin>>N;
    for(int i=1;i<=N-1;i++) {
        int u,v;
        cin>>u>>v;
        edges[u].push_back(v);
        edges[v].push_back(u);
    }
    
    for(int i=1;i<=N;i++) {
        range[i]=make_pair(-Inf,+Inf);
        isset[i]=false;
    }
    
    
    
    
    
    
    int K;
    cin>>K;
    for(int i=1;i<=K;i++) {
        int v,p;
        cin>>v>>p;
        isset[v]=true;
        range[v]=make_pair(p,p);
    }
    
    for(int i=1;i<=N;i++) {
        for(int j=0;j<edges[i].size();j++) {
            if (!isset[edges[i][j]])
                unset_edges[i].push_back(edges[i][j]);
        }
    }
    
    
    bool ok = true;
    bool change = false;
    for(int v=1;v<=N;v++) {
        if (isset[v]) {
            for(int j=0;j<unset_edges[v].size();j++) {
                ok &= dfs(v,unset_edges[v][j],range[v]);
                if (!ok)
                    break;
            }
        }
        if (!ok)
            break;
    }
    
    
    if (ok) {
        for(int v=1;v<=N;v++) {
            if (isset[v]) {
                answer[v]=range[v].first;
                for(int j=0;j<edges[v].size();j++) {
                    ok &= dfs2(v,edges[v][j],range[v].first);
                    if (!ok)
                        break;
                }
                if (!ok)
                    break;
                break;
            }
            if (!ok)
                break;
        }
    }
    
    
    if (ok) {
        cout << "Yes" << endl;
        
        for(int v=1;v<=N;v++) {
            cout << answer[v] << endl;
        }
        
        
    } else {
        cout << "No" << endl;
    }
    
    
  
    
    
}

Measured memory_bytes: 57984