#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <queue>
using namespace std;
int n,k,d[100005];
vector <int> g[100005];
int main()
{
	memset(d,0x3f3f3f3f,sizeof(d));
	cin>>n;
	for (int i=0;i<n-1;++i)
	{
		int x,y;
		cin>>x>>y;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	priority_queue <pair <int,int> > q;
	cin>>k;
	for (int i=0;i<k;++i)
	{
		int v,p;
		cin>>v>>p;
		d[v]=p;
		q.push(make_pair(p,v));
	}
	while (!q.empty())
	{
		int u=q.top().second;q.pop();
		for (int i=0;i<g[u].size();++i)
		{
			int v=g[u][i];
			if (d[v]==0x3f3f3f3f)
			{
				d[v]=d[u]-1;
				q.push(make_pair(d[v],v));
			}
		}
	}
	for (int i=1;i<=n;++i)
	{
		for (int j=0;j<g[i].size();++j)
		{
			if (abs(d[i]-d[g[i][j]])!=1)
			{
				cout<<"No\n";
				return 0;
			}
		}
	}
	cout<<"Yes\n";
	for (int i=1;i<=n;++i) cout<<d[i]<<endl;
}