#ifndef UTIL_INCLUDED
#define UTIL_INCLUDED

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
// #define DEBUGGING

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T, typename U> using P = pair<T, U>;
using ll = int64_t;
using PLL = P<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename Head, typename... Tail> const Head& var_min(const Head &head, const Tail&... tail) { return min(head, var_min(tail...)); }
template <typename Head, typename... Tail> const Head& var_max(const Head &head, const Tail&... tail) { return max(head, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }

namespace __init {

struct InitIO {
    InitIO() {
        cin.tie(0);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifndef DEBUG_FILE
#ifdef DEBUGGING
#include "../debug.cpp"
#else
#define DEBUG(...) 0
#endif
#endif

#endif

const ll INF = 5e15;

ll N;
V<ll> Pv;
VV<ll> edges;
V<bool> written;
VV<PLL> cranges;
PLL error = make_pair(INF, -INF);

void merge(PLL &ro, const PLL rm) {
    if(rm == error || ro == error) {
        ro = error;
        return;
    }
    chmax(ro.first, rm.first);
    chmin(ro.second, rm.second);
    if(ro.first >= ro.second) ro = error;
}

PLL dfs(ll now, ll pre, PLL npar) {
    DEBUG(now);
    if(written[now]) npar = make_pair(Pv[now], Pv[now] + 1);
    PLL range = npar;
    npar.first--;
    npar.second++;
    for(ll nxt : edges[now]) {
        if(nxt == pre) {
            cranges[now].push_back(error);
            continue;
        }
        auto cr = dfs(nxt, now, npar);
        cranges[now].push_back(cr);
        merge(range, cr);
    }
    range.first--;
    range.second++;
    return range;
}

bool in_range(const PLL &range, ll v) { return range.first <= v && v < range.second; }

void dfs(ll now, ll pre, ll val, bool &suc) {
    if(written[now] && Pv[now] != val) suc = false;
    Pv[now] = val;
    for(ll i = 0; i < edges[now].size(); i++) {
        ll nxt = edges[now][i];
        if(nxt == pre) continue;
        PLL range = cranges[now][i];
        if(in_range(range, val + 1)) dfs(nxt, now, val + 1, suc);
        else if(in_range(range, val - 1)) dfs(nxt, now, val - 1, suc);
        else suc = false;
    }
}

bool check(ll now, ll pre) {
   if(pre != -1 && abs(Pv[now] - Pv[pre]) != 1) return false;
   bool ret = true;
   for(ll nxt : edges[now]) {
       if(nxt == pre) continue;
       ret &= check(nxt, now);
   }
   return ret;
}

bool solve() {
    cin >> N;
    Pv = V<ll>(N);
    edges = VV<ll>(N);
    written = V<bool>(N, false);
    cranges = VV<PLL>(N);
    for(ll i = 1; i < N; i++) {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        edges[a].push_back(b);
        edges[b].push_back(a);
    }
    ll K;
    cin >> K;
    ll pidx = -1;
    for(ll i = 0; i < K; i++) {
        ll v, p;
        cin >> v >> p;
        v--;
        written[v] = true;
        Pv[v] = p;
        pidx = v;
    }
    auto status = dfs(pidx, -1, make_pair(Pv[pidx], Pv[pidx] + 1));
    if(status == error) return false;
    bool suc = true;
    dfs(pidx, -1, Pv[pidx], suc);
    return (suc & check(0, -1));
}

int main() {
    bool suc = solve();
    if(suc) {
        cout << "Yes\n";
        for(ll e : Pv) cout << e << endl;
    } else {
        cout << "No\n";
    }
    return 0;
}


Measured memory_bytes: 25216