/*
                ____________    ______________       __
               / _________  /\ /_____   _____/\     / /\
              / /\       / /  \\    /  /\    \ \   / /  \
             / /  \_____/ /   / \__/  /  \____\/  / /   /
            / /   /    / /   /    /  /   /       / /   /
           / /   /    / /   /    /  /   /       / /   /
          / /   /    / /   /    /  /   /       / /   /
         / /___/____/ /   /    /  /   /       / /___/________
        /____________/   /    /__/   /       /______________/\
        \            \  /     \  \  /        \              \ \
         \____________\/       \__\/          \______________\/
           ___       ___               ___    __________
          /  /\     /  /\             /  /\  /_______  /\
         /  /__\___/  /  \           /  /  \ \      /  /  \
        /____    ____/   /          /  /   /  \____/  /   /
        \   /   /\   \  /          /  /   /       /  /   /
         \_/   /  \___\/ ___      /  /   /       /  /   /
          /   /   /     /  /\    /  /   /       /  /   /
         /   /   /     /  /__\__/  /   /       /  /___/____
        /___/   /     /___________/   /       /___________/\
        \   \  /      \           \  /        \           \ \
         \___\/        \___________\/          \___________\/
       
          A FAN OF FIZZYDAVID
           
*/

#include<bits/stdc++.h>

#define HEAP priority_queue
#define rep(i,n) for(int i=0;i<(n);i++)
#define per(i,n) for(int i=(n)-1;i>=0;i--)
#define forn(i,l,r) for(int i=(l);i<=(r);i++)
#define nrof(i,r,l) for(int i=(r);i>=(l);i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define X first
#define Y second
#define eps 1e-20
#define pi 3.1415926535897932384626433832795
#define orz int
#define yjz main
#define fizzydavid return
#define ak 0
#define la ;
#define debug puts("OK");
#define SZ(x) (int)x.size()
#define ALL(x) x.begin(),x.end()

using namespace std;

typedef long long LL;
typedef double flt;
typedef vector<int> vi;
typedef pair<int,int> pii;

const int iinf=1e9+7;
const LL linf=1ll<<60;
const flt dinf=1e10;

template <typename T>
inline void scf(T &x)
{
	bool f=0; x=0; char c=getchar();
	while((c<'0' || c>'9') && c!='-') c=getchar();
	if(c=='-') { f=1; c=getchar(); }
	while(c>='0' && c<='9') { x=x*10+c-'0'; c=getchar(); }
	if(f) x=-x; return;
}

template <typename T1,typename T2>
void scf(T1 &x,T2 &y) { scf(x); return scf(y); }

template <typename T1,typename T2,typename T3>
void scf(T1 &x,T2 &y,T3 &z) { scf(x); scf(y); return scf(z); }

#ifdef ONLINE_JUDGE
#else
#define DEBUG
#endif

//---------------------------head----------------------------

const int N=1e5+100;

int n;
int v[N];
bool f[N];
vi g[N];
int dep[N],mn[N];

inline void dfs1(int u=1,int par=0)
{
	dep[u]=dep[par]+1;
	for(auto v:g[u]) if(v!=par) dfs1(v,u);
	return;
}

inline void dfs2(int u=1,int par=0)
{
	mn[u]=(f[u]?v[u]:-iinf);
	for(auto v:g[u]) if(v!=par){ dfs2(v,u); if(!f[u]) mn[u]=max(mn[v],mn[u]); }
	return;
}

inline void dfs3(int u=1,int par=0)
{
	if(par && !f[u]) mn[u]=max(mn[u],mn[par]-2);
	for(auto v:g[u]) if(v!=par) dfs3(v,u);
	return;
}

inline void check(int u=1,int par=0)
{
	if(par){ if(mn[u]!=mn[par]-2 && mn[u]!=mn[par]){ puts("No"); exit(0); } }
	for(auto v:g[u]) if(v!=par) check(v,u);
	return;
}

orz yjz()
{
	scf(n);
	rep(i,n-1)
	{
		int u,v; scf(u,v);
		g[u].pb(v); g[v].pb(u);
	}
	dfs1();
	int k; scf(k);
	rep(i,k)
	{
		int u,x; scf(u,x);
		v[u]=x-dep[u]; f[u]=1;
	}
	dfs2();
	dfs3();
	check();
	puts("Yes");
	forn(i,1,n) printf("%d\n",mn[i]+dep[i]);
	fizzydavid ak la
}

Measured memory_bytes: 10752