#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <cmath>
#include <math.h>
#include <string>
#include <time.h>
#include <random>
#include <memory.h>
#include <bitset>
using namespace std;

#define FILE0
#define MAGIC0
mt19937 rnd(time(0)); //rnd()

#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define mii map<int, int>
#define mll map<ll, ll>
#define msl map<string, ll>
#define mls map<ll, string>
#define MOD (1000000007)
#define MOD2 (1000000009ll)
#define BIGMOD (1000000000000000007ll)
#define RMOD int(5e8 + rnd() % (int) 5e8)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#ifdef FILE1
ifstream in("input.txt");
ofstream out("output.txt");
#endif
#ifdef MAGIC1
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#endif

bool isPrime(ll a)
{
	ll i;
	for (i = 2; i*i <= a; i++)
	{
		if (a%i == 0)
		{
			return 0;
		}
	}
	return (a != 1);
}

bool isPalindrom(const string &s, int l, int r)
{
	for (int i = 0; i < (r - l + 1) / 2; i++)
	{
		if (s[l + i] != s[r - i])
		{
			return 0;
		}
	}
	return 1;
}

template <class type1> type1 gcd(type1 a, type1 b)
{
	type1 t;
	while (b)
	{
		t = b;
		b = a%b;
		a = t;
	}
	return a;
}

ll positiveMod(ll v, ll md)
{
	v = v%md;
	if (v < 0)
	{
		v += md;
	}
	return v;
}

//-----------------------------------------------------end--------------------------------------//

vector <int> gr[100005];

pii res[100005];
int used[100005];
int sz[100005];

int unreal;

int dfsSz(int v, int pr)
{
	sz[v] = 1;

	for(auto it:gr[v])
	{
		if (used[it] == 0 && it != pr)
		{
			sz[v] += dfsSz(it, v);
		}
	}

	return sz[v];
}

int getCentroid(int v, int pr, int tn)
{
	for (auto it : gr[v])
	{
		if (used[it] == 0 && it != pr && sz[it] * 2 > tn)
		{
			return getCentroid(it, v, tn);
		}
	}
	
	return v;
}

pii dfs(int v, int pr)
{
	if (res[v].first != -MOD)
	{
		return{ res[v].first - 1, res[v].second + 1 };
	}

	pii tr = { -MOD, MOD };

	for (auto it : gr[v])
	{
		if (it != pr)
		{
			pii tr2 = dfs(it, v);

			if (tr2.first == -MOD)
			{
				continue;
			}

			if (tr2.first < 0)
			{
				tr2.first += 2;
			}

			if (tr.first == -MOD)
			{
				tr = tr2;
			}
			else
			{
				if (tr.first % 2 != tr2.first % 2)
				{
					unreal = 1;
				}
				else
				{
					pii tr3 = { max(tr.first, tr2.first), min(tr.second, tr2.second) };

					if (tr3.first > tr3.second)
					{
						unreal = 1;
					}

					tr = tr3;
				}
			}
		}
	}

	return{ max(-MOD, tr.first - 1), min(MOD, tr.second + 1) };
}

void buildCentroidDecomposition(int v)
{
	int tn = dfsSz(v, -1);

	int centroid = getCentroid(v, -1, sz[v]);

	if (res[centroid].first == -MOD)
	{
		res[centroid] = dfs(centroid, -1);
		res[centroid].first++;
		res[centroid].second--;
	}

	used[centroid] = 1;
	for (auto it : gr[centroid])
	{
		if (used[it] == 0)
		{
			buildCentroidDecomposition(it);
		}
	}
}


int main()
{
	fast;

	for (auto& it : res)
	{
		it = { -MOD, MOD };
	}

	int n, k, i, j, a, b, c;

	cin >> n;
	for (i = 0; i < n - 1; i++)
	{
		cin >> a >> b;

		gr[a].push_back(b);
		gr[b].push_back(a);
	}
	cin >> k;
	for (i = 0; i < k; i++)
	{
		cin >> a >> b;

		res[a] = { b, b };
	}

	buildCentroidDecomposition(1);

	if (unreal == 0)
	{
		for (i = 1; i <= n; i++)
		{
			for (auto it : gr[i])
			{
				if (abs(res[i].first - res[it].first) != 1)
				{
					unreal = 1;
				}
			}
		}
	}

	if (unreal == 1)
	{
		cout << "No\n";
	}
	else
	{
		cout << "Yes\n";

		for (i = 1; i <= n; i++)
		{
			cout << res[i].first << "\n";
		}
	}



	return 0;
}

Measured memory_bytes: 12672