#include <bits/stdc++.h>
using namespace std;

const int Maxn = 111111;
struct Edge {
	int v;
	Edge *nxt;
} pool[Maxn*2], *tree[Maxn], *tail = pool;
inline void addedge(const int &u, const int &v) {
	tail->v = v;
	tail->nxt = tree[u], tree[u] = tail++;
}

int n, k, a[Maxn];
bool visited[Maxn];
priority_queue<pair<int, int>> heap;

void solve() {
	for (int u; !heap.empty(); ) {
		u = heap.top().second, heap.pop();
		for (Edge *p = tree[u]; p; p = p->nxt) {
			if (!visited[p->v]) {
				a[p->v] = a[u]-1;
				visited[p->v] = true;
				heap.push({a[p->v], p->v});
			} else {
				if (abs(a[p->v]-a[u]) != 1) {
					puts("No");
					return;
				}
			}
		}
	}
	puts("Yes");
	for (int i = 1; i <= n; ++i) {
		printf("%d\n", a[i]);
	}
}

int main() {
	scanf("%d", &n);
	for (int i = 1, x, y; i < n; ++i) {
		scanf("%d%d", &x, &y);
		addedge(x, y), addedge(y, x);
	}
	scanf("%d", &k);
	for (int x, y; k--; ) {
		scanf("%d%d", &x, &y);
		a[x] = y;
		visited[x] = true;
		heap.push({y, x});
	}
	solve();
	return 0;
}