#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define mset(x, y) memset(x, y, sizeof x)
#define mcpy(x, y) memcpy(x, y, sizeof x)
using namespace std;

typedef long long LL;
typedef pair <int, int> pii;

inline int Read()
{
	int x = 0, f = 1, c = getchar();
	for (; !isdigit(c); c = getchar())
		if (c == '-')
			f = -1;
	for (;  isdigit(c); c = getchar())
		x = x * 10 + c - '0';
	return x * f;
}

const int MAXN = 100005;
const int INF = 0x3f3f3f3f;

priority_queue <pii> q;
vector <int> adj[MAXN];
int n, m, f[MAXN];

int main()
{
#ifdef wxh010910
	freopen("data.in", "r", stdin);
#endif
	n = Read(), mset(f, INF);
	for (int i = 1, x, y; i < n; i ++)
		x = Read(), y = Read(), adj[x].pb(y), adj[y].pb(x);
	m = Read();
	for (int i = 1, x, y; i <= m; i ++)
		x = Read(), y = Read(), f[x] = y, q.push(mp(y, x));
	while (!q.empty())
	{
		int x = q.top().yy; q.pop();
		for (auto y : adj[x])
			if (f[y] == INF)
				f[y] = f[x] - 1, q.push(mp(f[y], y));
			else if (abs(f[x] - f[y]) ^ 1)
				return puts("No"), 0;
	}
	puts("Yes");
	for (int i = 1; i <= n; i ++)
		printf("%d\n", f[i]);
	return 0;
}
