#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define sz(x) ((int)(x).size())
#define rep(i,a,b) for (int i=(a); i<(b); i++)
#define debug(x) cout << #x << " => " << x << endl
const int MAX_N = 7 + 100000;
vector<int> G[MAX_N];
///----------------------------------------------
int val[MAX_N];
pii tab[MAX_N];
pii dfs(int u,int p,int type) {
    pii ret=~val[u]?mp(val[u],val[u]):mp(0,100000);
    //debug(u);
    rep(i,0,sz(G[u])) {
        int v=G[u][i];
        if (v==p) continue;
        pii tmp=dfs(v,u,type^1);
        ret.fi=max(ret.fi,tmp.fi-1);
        ret.se=min(ret.se,tmp.se+1);
    }
    if ((ret.fi&1)!=type) ret.fi++;
    if ((ret.se&1)!=type) ret.se--;
    if (ret.fi>ret.se) { puts("No"); exit(0); }
    tab[u]=ret;
    return ret;
}

void print(int u,int p) {
    //debug(u);
    rep(i,0,sz(G[u])) {
        int v=G[u][i];
        if (v==p) continue;
        if (!~val[v]) {
            tab[v].fi=max(tab[v].fi,val[u]-1);
            val[v]=tab[v].fi;
        }
        print(v,u);
    }
}
///----------------------------------------------
int main() {

    ///freopen ( "xx.in" , "r" , stdin );

    ///init
    memset(val,-1,sizeof(val));

    ///read
    int n; cin>>n;
    rep(i,1,n) {
        int a,b; scanf("%d%d",&a,&b);
        G[a].pb(b);
        G[b].pb(a);
    }
    int m; cin>>m; int beg;
    rep(i,0,m) {
        int v,p; scanf("%d%d",&v,&p);
        val[v]=p;
        beg=v;
    }

    ///
    dfs(beg,0,val[beg]&1); puts("Yes");
    print(beg,0);
    rep(i,1,n+1) printf("%d\n",val[i]);

}
