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

#define NDEBUG
#include <cassert>


typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair

template <class T> inline void setmin(T & a, T const & b) { a = min(a, b); }
template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }


inline int parity(int x){ return !(x & 1); }

ii aggr(vector<ii>& cond) {
    if (cond.size() == 1) return cond[0];

    int lo = INT_MIN, hi = INT_MIN;

    for (int i=0; i<cond.size(); ++i) {
        int p = cond[i].first, d = cond[i].second;
        if (p == INT_MIN) continue;

        int loi = p - d, hii = p + d;
        if (lo == INT_MIN) {
            lo = loi; hi = hii;
        } else {
            if (parity(lo) != parity(loi)) return ii(INT_MIN, INT_MIN);
            if (hii < lo || hi < loi) return ii(INT_MIN, INT_MIN);
            lo = max(lo, loi); hi = min(hi,hii);
        }
    }

    if (lo == INT_MIN) return ii(INT_MIN, INT_MIN);
    else return ii( (lo+hi)/2, (hi-lo)/2 );
}

ii resolve(map<int,ii>& cond){
    vii xs;
    for (auto p: cond) xs.pb(p.second);
    return aggr(xs);
}

bool solve(int N, vi& a, vi& b, int K, vi& v, vi& p) {
    vvi nxt(N);
    rep(i,N-1) {
        nxt[a[i]].pb(b[i]);
        nxt[b[i]].pb(a[i]);
    }
    vi fixed(N, -1);
    rep(i,K){
        fixed[v[i]] = p[i];
    }

    vector<map<int,ii>> cond(N);

    queue<vi> q;
    rep(i,K){
        int here = v[i];
        cond[here][here] = ii(p[i], 0);
        for (int to: nxt[here]) {
            q.push(vi{ to, here, p[i], 1 });
        }
    }
    rep(here,N){
        if (fixed[here] == -1 && nxt[here].size() == 1) {
            for (int to: nxt[here]) {
                q.push(vi{ to, here, INT_MIN, INT_MIN });
            }
        }
    }

    while (!q.empty()) {
        vi t = q.front(); q.pop();
        int here=t[0], from=t[1], pi=t[2], diff=t[3];
        cond[here][from] = ii(pi,diff);

        if (fixed[here] != -1) {
            vii xs; xs.pb(ii(fixed[here], 0)); xs.pb(ii(pi, diff));
            if (aggr(xs).second == INT_MIN) return false;
            continue;
        }

        int ins = cond[here].size();
        int ways = nxt[here].size();
        if (ins == ways) {
            ii aggrd = resolve(cond[here]);
            if (aggrd.second == -1) return false;
            fixed[here] = aggrd.first + aggrd.second;

            for (int to: nxt[here]) {
                if (found(cond[to], here)) continue;
                q.push(vi{ to, here, fixed[here], 1 });
            }
        } else if (ways == ins+1) {
            vii xs;
            int to = -1;
            for (int from: nxt[here]) {
                if (found(cond[here], from)) xs.pb(cond[here][from]);
                else to = from;
            }
            ii aggrd = aggr(xs);
            if (aggrd.second == -1) return false;
            q.push(vi{ to, here, aggrd.first, aggrd.second+1 });
        }
    }

    printf("Yes\n");
    rep(i,N){
        printf("%d\n", fixed[i]);
    }
    return true;
}

int main() {
    int N; scanf("%d",&N);
    vi a(N-1), b(N-1);
    rep(i,N-1){
        scanf("%d%d",&a[i],&b[i]);
        --a[i]; --b[i];
    }
    int K; scanf("%d",&K);
    vi v(K), p(K);
    rep(i,K){
        scanf("%d%d",&v[i],&p[i]);
        --v[i];
    }
    if (!solve(N,a,b,K,v,p)){
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 34048