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

struct Node{
	int x, id;
	Node(){}
	Node(int _x, int _id){x = _x, id = _id;}
	bool operator < (const Node &A) const{
		return id > A.id;
	}
};

vector <int> from[100010];
priority_queue <Node> q;
int id[100010];

int main(){
	int n;
	scanf("%d", &n);
	for (int i = 1; i < n; i++){
		int u, v;
		scanf("%d%d", &u, &v);
		from[u].push_back(v);
		from[v].push_back(u);
	}
	int m;
	scanf("%d", &m);
	memset(id, -1, sizeof(id));
	for (int i = 0; i < m; i++){
		int a, b;
		scanf("%d%d", &a, &b);
		id[a] = b;
		q.push(Node(a, b));
	}
	while (!q.empty()){
		Node t = q.top(); q.pop();
		int u = t.x;
		for (int i = 0; i < from[u].size(); i++){
			int v = from[u][i];
			if (id[v] == -1) id[v] = t.id + 1, q.push(Node(v, t.id + 1));
		}
	}
	bool pd = 0;
	for (int i = 1; i <= n; i++){
		for (int j = 0; j < from[i].size(); j++){
			int v = from[i][j];
			if (abs(id[i] - id[v]) != 1){
				pd = 1;
				break;
			}
		}
		if (pd) break;
	}
	if (pd){
		printf("No\n");
		return 0;
	}
	printf("Yes\n");
	for (int i = 1; i <= n; i++){
		printf("%d\n", id[i]);
	}
	return 0;
}
