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

typedef long long ll;
typedef pair<int, int> ii; 

const int maxn = 1e5 + 10;
vector<int> adj[maxn]; 
int p[maxn], n, k, d[maxn];

int main(int argc, char const *argv[]) {
#ifdef LOCAL_TESTING
	freopen("in", "r", stdin);
#endif
	scanf("%d", &n);
	for(int i = 1; i < n; i++) {
		int u, v;
		scanf("%d %d", &u, &v);
		adj[u].push_back(v);
		adj[v].push_back(u);
	} scanf("%d", &k);
	memset(p, -1, sizeof p);
	
	priority_queue<ii, vector<ii>, greater<ii> > q;
	for(int i = 0; i < k; i++) {
		int u; scanf("%d", &u);
		scanf("%d", &p[u]);
		q.push({p[u], u});
	} 
	while(!q.empty()) {
		ii x = q.top(); q.pop(); 
		int val = x.first, u = x.second; 
		for(int v : adj[u]) {
			if(p[v] == -1) {
				p[v] = val + 1;
				q.push({p[v], v});
			}
			else if(abs(p[v] - p[u]) != 1) {
				puts("No"); return 0;
			}
		}
	}
	puts("Yes");
	for(int i = 1; i <= n; i++) {
		printf("%d\n", p[i]);
	}

}