/*Bismillahir Rahmanir Rahim*///{
#include <bits/stdc++.h>
#include <ext/numeric>
using namespace std; using __gnu_cxx::power;
using ll = long long; using ull = unsigned long long; using ld = long double;
const ll llinf = (1ll<<61)-1;
const double eps = 1e-6, ldeps = 1e-9;
struct Dbg {
static constexpr auto &os = cout;   // replace by cerr in interactive.
template<class C> static auto dud(C *x)->decltype(os << *x, 0);
template<class C> static char dud(...);
template<class C> typename enable_if<sizeof dud<C>(0)!=1, Dbg&>::type operator<<(const C &x) { os << x; return *this; }
template<class C> Dbg &dump(C b, C e) {
    *this << "\n[";
    int cur = 0;
    for (C i = b; i!=e and cur<26; i++, cur++) *this << ", "+2*(i==b) << *i;
    return *this << ']';
}
template<class C> typename enable_if<sizeof dud<C>(0)==1, Dbg&>::type operator<<(const C &x) {
    return dump(begin(x), end(x));
}
template<class C, size_t X> typename enable_if<!is_same<C, const char>::value, Dbg&>::type operator <<(C (&x)[X]) {
    return dump(begin(x), end(x));
}
template<class B, class C> Dbg &operator <<(const pair<B, C> &x) {
    return *this << '{' << x.first << ", " << x.second << '}';
}
Dbg &operator<<(ostream&(*x)(std::ostream&)) { os << x; return *this; }
} dbg;
void err(istringstream *iss) { delete iss; }
template<class C, class... Args> void err(istringstream *iss, const C &val, const Args &... args) {
    string name; *iss >> name; if (name.back()==',') name.pop_back();
    dbg << name << " = " << val << "; ", err(iss, args...);
}
#define bug(args...) dbg << __LINE__ << ": ", err(new istringstream(#args), args), dbg << endl
#define cbug(a, args...) if (a) bug(args);
#define ASSERT(a, o, b, args...) if (!((a)o(b))) bug(a, b, ##args), assert((a)o(b));
#define sl(a) int(strlen(a))
#define sz(a) int(a.size())
int T, Q, cn;//}
const int inf = 1000000007, mxn = 100005;
#define yes cout << "Yes\n"
#define no cout << "No\n", exit(0)

int n, K, val[mxn];
list<int> g[mxn];

pair<int, int> dp[mxn];
void dfsnich(const int &u, const int &p) {
    if (val[u]!=-1) dp[u] = {val[u], val[u]};
    for (auto &v : g[u]) if (v!=p) {
        dfsnich(v, u);
        if (dp[v] == make_pair(-inf, inf)) continue;
        if (dp[u] == make_pair(-inf, inf)) dp[u] = make_pair(dp[v].first-1, dp[v].second+1);
        else if ((dp[u].first&1) == (dp[v].first&1)) no;
        else dp[u].first = max(dp[u].first, dp[v].first-1), dp[u].second = min(dp[u].second, dp[v].second+1);
    }
}

void dfsupor(const int &u, const int &p) {
    if (dp[u] == make_pair(-inf, inf)) return;
    for (auto &v : g[u]) if (v!=p) {
        if (dp[v] == make_pair(-inf, inf)) dp[v] = make_pair(dp[u].first-1, dp[u].second+1);
        else if ((dp[v].first&1) == (dp[u].first&1)) no;
        else dp[v].first = max(dp[v].first, dp[u].first-1), dp[v].second = min(dp[v].second, dp[u].second+1);
        dfsupor(v, u);
    }
}

void dfsval(const int &u, const int &p) {
    if (dp[u].first > dp[u].second) no;
    for (auto &v : g[u]) if (v!=p) {
        if (val[u]+1 >= dp[v].first and val[u]+1 <= dp[v].second) val[v] = val[u]+1;
        else if (val[u]-1 >= dp[v].first and val[u]-1 <= dp[v].second) val[v] = val[u]-1;
        else no;
        dfsval(v, u);
    }
}

signed main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); cout.precision(11);
    cin >> n;
    for (int i = 0; i < n-1; i++) {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v), g[v].push_back(u);
    }
    memset(val, -1, sizeof(val)), fill_n(dp+1, n, make_pair(-inf, inf));
    cin >> K;
    for (int i = 0; i < K; i++) {
        int v;
        cin >> v;
        cin >> val[v];
    }

    dfsnich(1, 0), dfsupor(1, 0);
    val[1] = dp[1].first, dfsval(1, 0);
    yes;
    for (int i = 1; i <= n; i++) {
        cout << val[i] << '\n';
    }
}

Measured memory_bytes: 14592