#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;
#define int long long

typedef int Weight;
struct Edge{
    int from, to;
    Weight weight;
    int rev;     // ネットワークフロー時の逆辺
	vector<int> vs;
    Edge(int from, int to, Weight weight) :
        from(from), to(to), weight(weight) { }
    Edge(int from, int to, Weight weight, int rev) :
        from(from), to(to), weight(weight), rev(rev){ }
};
bool operator < (const Edge &a, const Edge &b){
    if(a.weight != b.weight) return a.weight > b.weight;
    if(a.from != b.from) return a.from > b.from;
    return  a.to > b.to;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

typedef vector<Weight> Array;
typedef vector<Array> Matrix;

void addFlowEdge(Graph &g, int a, int b, Weight c){
    g[a].push_back(Edge(a, b, c, g[b].size()));
    g[b].push_back(Edge(b, a, 0, g[a].size() - 1));
}
void addUndirectedEdge(Graph &g, int a, int b, Weight c){
    g[a].push_back(Edge(a, b, c, g[b].size()));
    g[b].push_back(Edge(b, a, c, g[a].size() - 1));
}

void compress(const Graph &g, Graph &h, int v, int u, const vector<set<int>> &Q) {
	for(const Edge e: g[v]) {
		if(e.to == u) continue;
		int p = e.to, q = v;
		vector<int> vs;
		while(g[p].size() == 2 && Q[p].empty()) {
			vs.push_back(p);
			q = g[p][0].to != q ? g[p][0].to : g[p][1].to;
			swap(p,q);
		}
		addUndirectedEdge(h, v, p, (int)vs.size() + 1);
		h[v][h[v].size()-1].vs = vs;
		compress(g, h, p, q, Q);
	}
}

bool dfs(const Graph &g, int v, int u, vector<set<int>> &Q, vector<int> &B) {
	int any = 0;
	map<int,int> mp;

	for(const Edge e: g[v]) {
		if(e.to == u) continue;
		if(!dfs(g, e.to, v, Q, B)) {
			return false;
		}
		if(B[e.to]) {
			++any;
		} else {
			set<int> st;
			for(int t: Q[e.to]) {
				for(int i = -e.weight; i <= e.weight; i += 2) {
					st.insert(t + i);
				}
			}
			for(int t: st) {
				mp[t]++;
			}
		}
	}
	/*
	cout << ">"<< v << ":" << any;
	for(auto i: mp) {
		cerr << ",(" << i.first << "," << i.second << ")";
	}
	cout << endl;
	*/
	if(Q[v].size() > 0) {
		return mp[*(Q[v].begin())] + any == g[v].size() - 1;
	} else if(any == g[v].size() - 1) {
		B[v] = true;
		return true;
	} else {
		for(pair<int,int> p: mp) {
			if(p.second + any == g[v].size() - 1) {
				Q[v].insert(p.first);
			}
		}
		return Q[v].size() > 0;
	}
}

void color(const Graph &g, int v, int u, vector<int> &C, const vector<set<int>> &Q, const vector<int> &B) {
	for(Edge e: g[v]) {
		if(e.to == u) continue;
		if(B[e.to] == 1) {
			C[e.to] = C[v] + e.weight;
		} else {
			for(int t: Q[e.to]) {
				int d = abs(t - C[v]);
				if(d <= e.weight && d % 2 == e.weight % 2) {
					C[e.to] = t;
					break;
				}
			}
		}
		int m = C[v];
		for(int i = 0; i < e.vs.size(); ++i) {
			if(C[e.to] >= m) {
				++m;
			} else {
				--m;
			}
			C[e.vs[i]] = m;
		}
		color(g, e.to, v, C, Q, B);
	}
}

signed main(){
	int N;
	cin >> N;
	Graph g(N + 1), h(N + 1);
	vector<set<int>> Q(N + 1);
	for(int i = 0; i < N -1; ++i) {
		int A, B;
		cin >> A >> B;
		addUndirectedEdge(g, A, B, 1);
	}
	int K;
	cin >> K;
	for(int i = 0; i < K; ++i) {
		int V, P;
		cin >> V >> P;
		Q[V].insert(P);
	}
	compress(g, h, 1, 0, Q);
	addUndirectedEdge(h, 0, 1, 1);
	vector<int> B(N + 1);
	/*
	for(int i = 1; i <= N; ++i) {
		cout << i << ":";
		EACH(j, h[i]) cout << "(" << j->to << "," << j->weight << "),";
		cout << endl;
	}
	*/
	bool res = dfs(h, 1, 0, Q, B);
	if(!res) {
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	vector<int> C(N + 1);
	C[1] = *(Q[1].begin());
	color(h, 1, 0, C, Q, B);
	for(int i = 1; i <= N; ++i) {
		cout << C[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 95104