/*
                _____________   ______________       __
               / _________  /\ /_____   _____/\     / /\
              / /\       / /  \\    /  /\    \ \   / /  \
             / /  \_____/ /   / \__/  /  \____\/  / /   /
            / /   /    / /   /    /  /   /       / /   /
           / /   /    / /   /    /  /   /       / /   /
          / /   /    / /   /    /  /   /       / /   /
         / /___/____/ /   /    /  /   /       / /___/________
        /____________/   /    /__/   /       /______________/\
        \            \  /     \  \  /        \              \ \
         \____________\/       \__\/          \______________\/
           ___       ___               ___    ___________
          /  /\     /  /\             /  /\  /_______   /\
         /  /__\___/  /  \           /  /  \ \      /  /  \
        /____    ____/   /          /  /   /  \____/  /   /
        \   /   /\   \  /          /  /   /       /  /   /
         \_/   /  \___\/ ___      /  /   /       /  /   /
          /   /   /     /  /\    /  /   /       /  /   /
         /   /   /     /  /__\__/  /   /       /  /___/____
        /___/   /     /___________/   /       /___________/\
        \   \  /      \           \  /        \           \ \
         \___\/        \___________\/          \___________\/

          A FAN OF FIZZYDAVID

*/

#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <deque>
#include <queue>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <iomanip>
#include <utility>
#include <functional>
using namespace std;
//orz jzm
#define ll long long
#define ull unsigned ll
#define orz int
#define yjz main
#define fizzydavid return
#define ak 0
#define la ;
#define plusonesecond {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
#define minusonesecond exit(0)
const double EPS = 1e-8;
const ll PR = 19260817;
const ll inv2 = 500000004;
const ll inv3 = 333333336;
const int N = 100005;
int n, YHTS;
vector<int> G[N];
int val[N], Rl[N], Rr[N];
bool used[N];
bool dfs1(int u, int num) {
	used[u] = true;
	int nnum = (num + 1) & 1;
	for(int i = 0; i < G[u].size(); i++) {
		int v = G[u][i];
		if(used[v]) continue;
		if(val[v] != -1 && (val[v] & 1) != nnum) return false;
		if(!dfs1(v, nnum)) return false;
		Rl[u] = max(Rl[u], Rl[v] - 1);
		Rr[u] = min(Rr[u], Rr[v] + 1);
	}
	if(Rl[u]>Rr[u]) return false;
	return true;
}
void dfs2(int u) {
	used[u] = true;
	for(int i = 0; i < G[u].size(); i++) {
		int v = G[u][i];
		if(used[v]) continue;
		if(val[u]-1 >= Rl[v] && val[u]-1 <= Rr[v])
			val[v] = val[u] - 1;
		else
			val[v] = val[u] + 1;
		dfs2(v);
	}
}
orz yjz() {
	scanf("%d", &n);
	for(int i = 0; i < n; i++) {
		Rl[i] = -1000000000;
		Rr[i] = +1000000000;
	}
	for(int i = 0; i < n - 1; i++) {
		int u, v;
		scanf("%d%d", &u, &v);
		u--, v--;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	scanf("%d", &YHTS);
	int r;
	memset(val, -1, sizeof(val));
	while(YHTS--) {
		int u, pp;
		scanf("%d%d", &u, &pp);
		u--;
		r=u;
		val[u] = pp;
		Rl[u] = pp;
		Rr[u] = pp;
	}
	memset(used, false, sizeof(used));
	if(!dfs1(r, val[r] & 1)) {
		puts("No");
		return 0;
	}
	puts("Yes");
	memset(used, false, sizeof(used));
	dfs2(r);
	for(int i = 0; i < n; i++)
		printf("%d\n", val[i]);
	fizzydavid ak la
}

Measured memory_bytes: 15488