#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
/*#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
#pragma GCC target("avx2")  //Enable AVX*/

using namespace std;

using ll = long long;

#define mp make_pair

const int p = 998244353;


int mul(int a, int b) {
    return (1LL * a * b) % p;
}

int add(int a, int b) {
    int s = (a+b);
    if (s>=p) s-=p;
    return s;
}

int sub(int a, int b) {
    int s = (a+p-b);
    if (s>=p) s-=p;
    return s;
}

int po(int a, int deg)
{
    if (deg==0) return 1;
    if (deg%2==1) return mul(a, po(a, deg-1));
    int t = po(a, deg/2);
    return mul(t, t);
}

int inv(int n)
{
    return po(n, p-2);
}

/*struct DSU {
    vector<int> sz;
    vector<int> parent;

    void make_set(int v) {
        parent[v] = v;
        sz[v] = 1;
    }

    int find_set(int v) {
        if (v == parent[v])
            return v;
        return parent[v] = find_set(parent[v]);
    }

    void union_sets(int a, int b) {
        a = find_set(a);
        b = find_set(b);
        if (a != b) {
            if (sz[a] < sz[b])
                swap(a, b);
            parent[b] = a;
            sz[a] += sz[b];
        }
    }

    DSU(int n) {
        sz.resize(n);
        parent.resize(n);
        for (int i = 0; i < n; i++) make_set(i);
    }
};*/

/*const int N = 1000000;

vector<int> facs(N), invfacs(N);

void init()
{
    facs[0] = 1;
    for (int i = 1; i<N; i++) facs[i] = mul(facs[i-1], i);
    invfacs[N-1] = inv(facs[N-1]);
    for (int i = N-2; i>=0; i--) invfacs[i] = mul(invfacs[i+1], i+1);
}

int C(int n, int k)
{
    return mul(facs[n], mul(invfacs[k], invfacs[n-k]));
}*/

vector<vector<int>> G;
vector<int> a;

vector<bool> all;
vector<pair<int, int>> bound;

void dfs(int v, int par = -1)
{
    int l = -1e9; int r = 1e9;
    for (auto it: G[v]) if (it!=par)
    {
        dfs(it, v);
        if (!all[it])
        {
            if (l==-1e9)
            {
                l = bound[it].first - 1;
                r = bound[it].second + 1;
            }
            else
            {
                if ((l - bound[it].first - 1)%2)
                {
                    //cout<<"Here: "<<v<<'\n';
                    cout<<"No";
                    exit(0);
                }
                else
                {
                    l = max(l, bound[it].first - 1);
                    r = min(r, bound[it].second + 1);
                }
            }
        }
    }
    //cout<<v<<": "<<l<<' '<<r<<endl;
    if (a[v]!=-1)
    {
        if (l!=-1e9 && ((a[v] - l)%2 || (a[v]<l || a[v]>r)))
        {
            //cout<<"Here1: "<<v<<'\n';
            cout<<"No";
            exit(0);
        }
        else
        {
            bound[v] = mp(a[v], a[v]);
        }
    }
    else
    {
        if (l==-1e9) all[v] = true;
        else
        {
            if (l>r)
            {
                //cout<<"Here2: "<<v<<'\n';
                cout<<"No";
                exit(0);
            }
            else bound[v] = mp(l, r);
        }
    }
    //cout<<v<<": "<<all[v]<<' '<<bound[v].first<<' '<<bound[v].second<<endl;
}

void dfs1(int v, int par = -1)
{
    for (auto it: G[v]) if (it!=par)
    {
        if (all[it]) a[it] = a[v]-1;
        else if (bound[it].first<=a[v]-1) a[it] = a[v]-1;
        else a[it] = a[v]+1;
        dfs1(it, v);
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);

    int n;
    cin>>n;

    G.resize(n+1);
    for (int i = 0; i<n-1; i++)
    {
        int a, b;
        cin>>a>>b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    int k;
    cin>>k;

    a = vector<int>(n+1, -1);

    int v, x;
    for (int i = 0; i<k; i++)
    {
        cin>>v>>x;
        a[v] = x;
    }

    bound.resize(n+1);
    all.resize(n+1);
    dfs(1);
    a[1] = bound[1].first;
    dfs1(1);
    cout<<"Yes"<<endl;
    for (int i = 1; i<=n; i++) cout<<a[i]<<'\n';




}



Measured memory_bytes: 15360