#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long LL;
#define mp(a, b) make_pair(a, b)
#define fir first
#define sec second
template <class T> inline void read(T &a) {
	static int ch = 0; bool f = 0; a = 0;
	while (ch < '0' || ch > '9') f |= ch == '-', ch = getchar();
	while (ch >= '0' && ch <= '9') a = a * 10 + ch - '0', ch = getchar();
	if (f) a = -a;
}
//#define MULTI_CASE
#define MOD
#define N 100005

vector <int> E[N];

int n, K;
int V[N], P[N];
int L[N], R[N], a[N];

void solveL() {
	priority_queue <pii> q;
	for (int i = 1; i <= K; i++) q.push(mp(P[i], V[i]));
	while (!q.empty()) {
		pii o = q.top(); q.pop();
		if (L[o.sec] != o.fir) continue;
		for (auto v : E[o.sec]) {
			if (L[v] < o.fir - 1) {
				L[v] = o.fir - 1;
				q.push(mp(L[v], v));
			}
		}
	}
}

void solveR() {
	priority_queue <pii, vector <pii>, greater<pii> > q;
	for (int i = 1; i <= K; i++) q.push(mp(P[i], V[i]));
	while (!q.empty()) {
		pii o = q.top(); q.pop();
		if (R[o.sec] != o.fir) continue;
		for (auto v : E[o.sec]) {
			if (R[v] > o.fir + 1) {
				R[v] = o.fir + 1;
				q.push(mp(R[v], v));
			}
		}
	}
}

void dfs(int x, int fa) {
	for (auto v : E[x]) if (v != fa) {
		if (a[x] + 1 <= R[v]) a[v] = a[x] + 1;
		else a[v] = a[x] - 1;
		dfs(v, x);
	}
}


void work() {
	read(n);
	for (int i = 1; i < n; i++) {
		int u, v; read(u); read(v);
		E[u].push_back(v);
		E[v].push_back(u);
	}
	for (int i = 1; i <= n; i++) L[i] = -10 * N, R[i] = 10 * N;
	read(K);
	for (int i = 1; i <= K; i++) {
		read(V[i]); read(P[i]);
		L[V[i]] = R[V[i]] = P[i];
	}
	solveL();
	solveR();
	for (int i = 1; i <= n; i++) if (L[i] > R[i]) {
		puts("No"); return;
	}
	a[V[1]] = L[V[1]];
	dfs(V[1], -1);
	puts("Yes");
	for (int i = 1; i <= n; i++) {
		printf("%d\n", a[i]);
	}
}


int main() {
#ifdef MULTI_CASE
	int T;
	cin >> T;
	for (int i = 1; i <= T; i++) {
		printf("Case %d: ", i);
		work();
	}
#else
	work();
#endif
	return 0;
}