#include<iostream>
#include<cstdio>
#include<cstring>
#define inf 0x3f3f3f3f
using namespace std;
const int maxn = 100010;
int n, m, tot, head[maxn], ans[maxn], l[maxn], r[maxn];
bool flag = 1;
struct line {
    int to, nxt;
} edge[maxn * 2];

void add(int u, int v) {
    edge[++tot].to = v, edge[tot].nxt = head[u], head[u] = tot;
}

void check(int u, int fa) {
    l[u] = -inf - 1, r[u] = inf + 1;
    if(~ans[u]) l[u] = r[u] = ans[u];
    for(int i = head[u]; i; i = edge[i].nxt) {
        int v = edge[i].to;
        if(v != fa) {
            check(v, u);
            if(l[v] < -inf) continue;
            if(l[u] < -inf) {
                l[u] = l[v] - 1, r[u] = r[v] + 1;
            }
            else {
                if((abs(l[u]) & 1) == (abs(l[v]) & 1)) {
                    flag = 0;
                    return;
                }
                l[u] = max(l[u], l[v] - 1);
                r[u] = min(r[u], r[v] + 1);
            }
        }
    }
    if(l[u] > r[u]) flag = 0;
}

void make(int u, int fa) {
    for(int i = head[u]; i; i = edge[i].nxt) {
        int v = edge[i].to;
        if(v != fa) {
            if(ans[v] == -1) {
                if(l[v] <= ans[u] - 1 && ans[u] - 1 <= r[v]) ans[v] = ans[u] - 1;
                else ans[v] = ans[u] + 1;
            }
            make(v, u);
        }
    }
}

int main()
{
    scanf("%d", &n);
    for(int u, v, i = 1; i < n; i++) {
        scanf("%d %d", &u, &v);
        add(u, v), add(v, u);
    }
    memset(ans, -1, sizeof(ans));
    scanf("%d", &m);
    for(int u, p, i = 1; i <= m; i++) {
        scanf("%d %d", &u, &p);
        ans[u] = p;
    }
    check(1, 0);
    if(!flag) puts("No");
    else {
        puts("Yes");
        if(ans[1] == -1) ans[1] = l[1];
        make(1, 0);
        for(int i = 1; i <= n; i++) printf("%d\n", ans[i]);
    }
    return 0;
}

/*#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
using namespace std;
const int maxn = 100010;
int n, m, tot, head[maxn], ans[maxn];
struct node {
    int num, val;
    node(){}
    node(int a, int b) {
        num = a, val = b;
    }
    bool operator < (const node & a) const {
        return val > a.val;
    }
};
struct line {
    int to, nxt;
} edge[maxn * 2];

void add(int u, int v) {
    edge[++tot].to = v, edge[tot].nxt = head[u], head[u] = tot;
}

int main()
{
    scanf("%d", &n);
    for(int u, v, i = 1; i < n; i++) {
        scanf("%d %d", &u, &v);
        add(u, v), add(v, u);
    }
    memset(ans, -1, sizeof(ans));
    scanf("%d", &m);
    priority_queue <node> pq;
    for(int u, p, i = 1; i <= m; i++) {
        scanf("%d %d", &u, &p);
        ans[u] = p;
        pq.push(node(u, p));
    }
    while(!pq.empty()) {
        node u = pq.top();
        pq.pop();
        for(int i = head[u.num]; i; i = edge[i].nxt) {
            int v = edge[i].to;
            if(ans[v] == -1) {
                ans[v] = u.val + 1;
                pq.push(node(v, ans[v]));
            }
        }
    }
    for(int i = 1; i <= n; i++)
        for(int j = head[i]; j; j = edge[j].nxt)
            if(abs(ans[i] - ans[edge[j].to]) != 1) {
                puts("No");
                return 0;
            }
    puts("Yes");
    for(int i = 1; i <= n; i++) printf("%d\n", ans[i]);
    return 0;
}*/

Measured memory_bytes: 8704