#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <random>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;

typedef
tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> orderedSet;

#define pb push_back
#define F first
#define S second
#define all(a) (a).begin(), (a).end()

#define for1(i0, l0, r0) for (int i0 = l0; i0 < r0; ++i0)
#define for2(i0, l0, r0) for (int i0 = l0; i0 <= r0; ++i0)
#define forn(i0, n0) for (int i0 = 0; i0 < n0; ++i0)
#define forn1(i0, n0) for (int i0 = 1; i0 < n0; ++i0)
#define forr(i0, n0) for (int i0 = n0; i0 >= 0; --i0)
#define forr1(i0, r0, l0) for (int i0 = r0; i0 > l0; --i0)
#define forr2(i0, r0, l0) for (int i0 = r0; i0 >= l0; --i0)

#define Sort(a) sort(all(a))
#define Reverse(a) reverse(all(a))

typedef long double ld;
#define ui unsigned int
#define ull unsigned long long

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef pair<string, string> pss;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<bool> vb;
typedef vector<string> vs;

typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<pdd> vpdd;

typedef vector<vi> vvi;
typedef vector<vd> vvd;
typedef vector<vll> vvll;
typedef vector<vb> vvb;

#define vpss vector<pss>
#define vvs vector<vs>
#define vvpii vector<vpii>
#define vvpll vector<vpll>
#define vpt vector<pt>
#define vvvi vector<vvi>
#define vsi vector<set<int>>
#define ss second
#define ff first

#define printvi(arr) for (int x0 : arr) cout << x0 << ' '; cout << '\n';
#define printvll(arr) for (ll x0 : arr) cout << x0 << ' '; cout << '\n';
#define printpair(pair0) cout << pair0.F << ' ' << pair0.S << '\n';
#define printvp(arr) for (auto pair0 : arr) printpair(pair0);
#define initArray(arr, N0, X0) memset(arr, X0, N0 * sizeof(int))
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void init() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //cout.precision(16);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
}

const int maxn = 1e5;

vi a(maxn, -1);
vb e(maxn, 1), o(maxn, 1);
vi g[maxn];
vi l(maxn, -2e9), r(maxn, 2e9);

void dfs(int v, int p = -1) {
    for (int u : g[v]){
        if (u != p) dfs(u, v);
    }
    for (int u : g[v]){
        if (u == p) continue;
        l[v] = max(l[v], l[u] - 1);
        r[v] = min(r[v], r[u] + 1);
        if (!e[u]) o[v] = 0;
        if (!o[u]) e[v] = 0;
        if (!e[v] && !o[v]){
            cout << "No\n";
            exit(0);
        }
    }
    if (l[v] > r[v]){
        cout << "No\n";
        exit(0);
    }
    if (a[v] != -1){
        if (a[v] % 2 == 0){
            if (!e[v]) {
                cout << "No\n";
                exit(0);
            }
            o[v] = false;
        }
        if (a[v] % 2 == 1){
            if (!o[v]) {
                cout << "No\n";
                exit(0);
            }
            e[v] = false;
        }
        if (a[v] < l[v] || a[v] > r[v]){
            cout << "No\n";
            exit(0);
        }
        l[v] = r[v] = a[v];
    }
}

vi ans(maxn);

void go(int v, int p = -1, int L = -2e9, int R = 2e9){
    L = max(L, l[v]);
    R = min(R, r[v]);
    ans[v] = L;
    if (L % 2 == 0 && !e[v]) ans[v]++;
    if (L % 2 == 1 && !o[v]) ans[v]++;
    for (int u : g[v]){
        if (u == p) continue;
        if (ans[v] % 2 == 0) e[u] = 0; else o[u] = 0;
        go(u, v, L - 1, R + 1);
    }
}

void solve() {
    int n;
    cin >> n;
    forn1(i, n) {
        int v, u;
        cin >> v >> u;
        v--, u--;
        g[v].pb(u), g[u].pb(v);
    }
    int k;
    cin >> k;
    forn(i, k){
        int v, p;
        cin >> v >> p;
        v--;
        a[v] = p;
    }
    dfs(0);
    cout << "Yes\n";
    go(0);
    forn(i, n) cout << ans[i] << '\n';
}

bool multitest = false;

int main() {
    init();
    int t = 1;
    if (multitest) cin >> t;
    forn(i, t) solve();
}

Measured memory_bytes: 19536