#include <bits/stdc++.h>

using namespace std;

class segtree {
    struct node {
        long long v ; // default value for the leafs
        long long lazy = 0; // no lazy value

        void apply(int l, int r, long long x) {
            v -= x;
            // set v to the new value of range [l , r] when updated with x
        }

        void add_lazy(long long x) {
            lazy += x;
            // lazy combine
        }

        node operator +(const node &other) const {
            node ret;
            ret.v = min(v , other.v);
            // combine v with other.v
            return ret;
        }

        bool isLazy() {return lazy != 0;}
        void cancel() {lazy = 0;}
    };

    void push(int l, int r, int p) {
        if (tree[p].isLazy()) {
            tree[p].apply(l, r, tree[p].lazy);
            if (l != r) {
                tree[left(p)].add_lazy(tree[p].lazy);
                tree[right(p)].add_lazy(tree[p].lazy);
            }
            tree[p].cancel();
        }
    }

    int left(int p) { return p << 1; }
    int right(int p) { return (p << 1) + 1; }

    int n;
    vector<node> tree;

    void build(int l, int r, int p, const vector<int> &v) {
        if (l == r) {
            tree[p].v = v[l];
            return;
        }
        int mid = (l + r) >> 1;
        build(l, mid, left(p), v);
        build(mid + 1, r, right(p), v);
        tree[p] = tree[left(p)] + tree[right(p)];
    }

    void update(int s, int e, long long v, int l, int r, int p) {
        push(l, r, p);
        if (l > e || r < s)
            return;
        if (l >= s && r <= e) {
            tree[p].apply(l, r, v);
            if (l != r) {
                tree[left(p)].add_lazy(v);
                tree[right(p)].add_lazy(v);
            }
            return;
        }
        int mid = (l + r) >> 1;
        update(s, e, v, l, mid, left(p));
        update(s, e, v, mid + 1, r, right(p));
        tree[p] = tree[left(p)] + tree[right(p)];
    }

    node query(int s , int e , int l , int r , int p) {
        push(l , r , p);
        if (l >= s && r <= e) return tree[p];
        int mid = (l + r) >> 1;
        if (e <= mid)
            return query(s , e , l , mid , left(p));
        else if (s > mid)
            return query(s , e , mid + 1 , r , right(p));
        return query(s , e , l , mid , left(p)) + query(s , e , mid + 1 , r , right(p));
    }

public:
    segtree(const vector<int> &v) : n(v.size()) {
        tree.resize(4 * n);
        build(0, n - 1, 1, v);
    }

    void update(int s, int e, long long v) {
        update(s, e, v, 0, n - 1, 1);
    }

    long long query(int s, int e) {
        return query(s, e, 0, n - 1, 1).v;
    }
} *st;

const int N = 1e5 + 5 , INF = 1e9;
int val[N];
int in[N] , out[N] , t;
int n;
vector<int> v;
vector<int> adj[N];

void dfs (int node , int par , int exp) {
    in[node] = t++;
    if(val[node] == -1){
        v.push_back(INF - exp);
    }else{
        v.push_back(val[node]-exp);
    }
    for(int nxt : adj[node])
        if(nxt != par)
            dfs(nxt , node , exp-1);
    out[node] = t-1;
}

void solve(int node , int par){
    if (st->query(in[node] , out[node]) > 1)
        st->update(in[node] , out[node] , 2);

    for(int nxt : adj[node])
        if(nxt != par)
            solve(nxt , node);
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.in" , "r" , stdin);
#endif
    cin >> n;

    for (int i = 0 ;i < n - 1 ;i++) {
        int u , v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    memset(val , -1 , sizeof val);

    int k , root;
    cin >> k;

    while (k--) {
        cin >> root;
        cin >> val[root];
    }

    dfs(root,-1,val[root]);
    st = new segtree(v);
    solve(root,-1);

    for(int i = 1 ; i <= n ; i++){
        if(val[i] == -1){
            val[i] = INF - st->query(in[i],in[i]);
        }else{
            if(st->query(in[i],in[i]) != 0){
                cout << "No" << endl;
                return 0;
            }
        }
    }

    cout << "Yes\n";
    for(int i = 1 ; i <= n ; i++)
        cout << val[i] << "\n";


    return 0;
}

Measured memory_bytes: 33844