#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;
using namespace std;

vector<vector<int> > g;
vector<int> pp;
vector<int> minp;
vector<int> maxp;
vector<int> flag;

bool dfs(int par, int curr, int mm_out[3])
{
    int siz=(int)g[curr].size();

    int mmall[3]={0,INF,-1};
    int i;
    for(i=0; i<siz; i++) {
        int next=g[curr][i];
        if(par==next) continue;

        int mm[3]={0,INF,-1};
        if(!dfs(curr, next, mm)) {
            return false;
        }
        mmall[0]=MAX(mmall[0],mm[0]);
        mmall[1]=MIN(mmall[1],mm[1]);
        if(mm[2]>=0) {
            if(mmall[2]>=0 && mmall[2]!=mm[2]) {
                return false;
            }
            if(mmall[2]<0) mmall[2]=mm[2];
        }
    }

    if(pp[curr]>=0) {
        if(pp[curr]<mmall[0] || pp[curr]>mmall[1]) {
            return false;
        }
        if(mmall[2]>=0 && pp[curr]%2!=mmall[2]) {
            return false;
        }
        mmall[0]=mmall[1]=pp[curr];
        mmall[2]=pp[curr]%2;
    }

    minp[curr]=mmall[0];
    maxp[curr]=mmall[1];
    flag[curr]=mmall[2];

    mmall[0]--;
    mmall[1]++;
    mm_out[0]=MAX(mm_out[0],mmall[0]);
    mm_out[1]=MIN(mm_out[1],mmall[1]);
    mm_out[2]=(mmall[2]<0? -1: 1-mmall[2]);

    return true;
}


bool dfs2(int par, int curr, int parval)
{
    int siz=(int)g[curr].size();

    if(pp[curr]>=0) {
        if(pp[curr]<minp[curr] || pp[curr]>maxp[curr]) {
            return false;
        }
        if(parval>=0 && (abs(pp[curr]-parval)!=1)) {
            return false;
        }
    }
    else if(parval>=0) {
        int t;
        for(t=0; t<2; t++) {
            pp[curr]=(t==0? parval-1: parval+1);
            if(pp[curr]>=minp[curr] && pp[curr]<=maxp[curr]) {
                break;
            }
        }
        if(t==2) {
            return false;
        }
    }
    else {
        if(minp[curr]>maxp[curr]) return false;
        pp[curr]=minp[curr];
    }

    int i;
    for(i=0; i<siz; i++) {
        int next=g[curr][i];
        if(par==next) continue;

        if(!dfs2(curr, next, pp[curr])) {
            return false;
        }
    }

    return true;
}

int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);

    g.resize(n);
    int i;
    for(i=0; i<n-1; i++) {
        int a,b;
        scanf("%d%d", &a, &b); a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    pp.resize(n);
    for(i=0; i<n; i++) {
        pp[i]=-1;
    }
    int K;
    scanf("%d", &K);
    for(i=0; i<K; i++) {
        int v,tmp;
        scanf("%d%d", &v, &tmp); v--;
        pp[v]=tmp;
    }

    minp.resize(n);
    maxp.resize(n);
    flag.resize(n);
    for(i=0; i<n; i++) {
        minp[i]=0;
        maxp[i]=INF;
        flag[i]=-1;
    }
    int mm[3]={0,INF,-1};
    if(!dfs(-1, 0, mm)) {
        printf("No\n"); return 0;
    }

    if(minp[0]>maxp[0]) {
        printf("No\n"); return 0;
    }

    if(!dfs2(-1,0,-1)) {
        printf("No\n"); return 0;
    }

    printf("Yes\n");
    for(i=0; i<n; i++) {
        printf("%d\n", pp[i]);
    }

    return 0;
}


Measured memory_bytes: 18944