#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
#include <stack>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"
#define popcnt(x) __builtin_popcount(x)

using ll = long long;
using P = pair<int, int>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
    cout << '(' << p.first << ", " << p.second << ')';
    return os;
}

template<class T>
void print(const vector<T> &v, const string &delimiter) { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }

vector<vector<int>> graph;

template<class Weight>
struct WeightedGraph {
    struct Edge{
        int to;
        Weight weight;
    };
    int n;
    vector<vector<Edge>> edges;
    Weight zero;
    Weight inf;
    WeightedGraph(int n, Weight zero, Weight inf) : n(n), edges(n), zero(zero), inf(inf) {}
    void add_edge(int u, int v, Weight w) { edges[u].push_back({v, w}); }
};

template<class Weight>
void dijkstra(int s, const WeightedGraph<Weight> &g, vector<Weight> &d) {
    using Node = pair<Weight, int>;
    priority_queue<Node, vector<Node>, greater<Node>> que;
    d.assign(g.n, g.inf);
    d[s] = g.zero;
    que.push(Node(g.zero, s));

    while (!que.empty()) {
        Node p = que.top(); que.pop();
        int v = p.second;
        if (d[v] < p.first) continue;
        for (int i = 0; i < (int)g.edges[v].size(); i++) {
            auto e = g.edges[v][i];
            if (d[e.to] > d[v] + e.weight) {
                d[e.to] = d[v] + e.weight;
                que.push(Node(d[e.to], e.to));
            }
        }
    }
}

int main() {
    int n;
    cin >> n;
    graph.resize(n);
    rep(i, n - 1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    
    WeightedGraph<int> g(n + 1, 0, 1000000000);
    rep(u, n - 1) for (int v: graph[u]) {
        g.add_edge(u, v, 1);
        g.add_edge(v, u, 1);
    }
    
    int k;
    cin >> k;
    vector<int> v(k), p(k);
    rep(i, k) {
        cin >> v[i] >> p[i];
        v[i]--;
        g.add_edge(n, v[i], p[i]);
    }
    
    vector<int> d;
    dijkstra(n, g, d);
    rep(i, k) if (d[v[i]] != p[i]) {
        cout << "No" << endl;
        return 0;
    }
    rep(u, n) for (int v: graph[u]) if (abs(d[u] - d[v]) != 1) {
        cout << "No" << endl;
        return 0;
    }
    
    cout << "Yes" << endl;
    rep(i, n) cout << d[i] << endl;
}

Measured memory_bytes: 17016