#include <queue>
#include <cstdio>
#include <cstring>

inline int Abs(const int x){return x>=0?x:-x;}

int n,k,c[100005];
int Head[100005],Next[200005],To[200005],En;
struct Rec
{
    int x,v;
    inline bool operator<(const Rec &o)const{return v>o.v;}
};
std::priority_queue<Rec> q;

inline void Add(const int x,const int y){Next[++En]=Head[x],To[Head[x]=En]=y;}

int main()
{
    scanf("%d",&n);
    for(int i=2,x,y;i<=n;++i)scanf("%d%d",&x,&y),Add(x,y),Add(y,x);
    scanf("%d",&k);
    memset(c,-1,sizeof c);
    for(int i=1,x,v;i<=k;++i)scanf("%d%d",&x,&v),c[x]=v,q.push((Rec){x,v});
    while(!q.empty())
    {
        int x=q.top().x,v=q.top().v;
        q.pop();
        for(int i=Head[x],y;i;i=Next[i])
            if(c[y=To[i]]==-1)
            {
                c[y]=v+1,q.push((Rec){y,v+1});
            }
            else if(Abs(c[y]-c[x])!=1)return puts("No"),0;
    }
    puts("Yes");
    for(int i=1;i<=n;++i)printf("%d\n",c[i]);
    return 0;
}