// Zhupengfei 2018
// This program / source file is in public domain.

// Solution for problem: Integers on a Tree 2

#include <bits/stdc++.h>

// Common definitions
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define repd(i, a, b) for (int i = (b); i >= (a); i--)
#if __cplusplus >= 201103L
#define foreach(it, container) for (it : (container))
#else
#define foreach(it, container)                                                                     \
    for (typeof((container).begin()) it = (container).begin(); it != (container).end(); ++it)
#endif
#define forever for (;;)

// Debug use
#ifdef LOCAL
#define dbg_out(x) cout << (x) << endl
#else
#define dbg_out(x)
#endif

// IO stream extensions
template <typename T>
std::ostream& operator<<(std::ostream& out, const std::vector<T>& v) {
    if (!v.empty()) {
        std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, " "));
    }
    return out;
}
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& out, const std::pair<T1, T2>& pa) {
    out << pa.first << " " << pa.second;
    return out;
}
template <typename T>
std::istream& operator>>(std::istream& is, std::vector<T>& v) {
    v.clear();
    size_t siz;
    is >> siz;
    v.reserve(siz);
    T value;
    for (size_t i = 0; i < siz; i++) {
        is >> value;
        v.push_back(value);
    }
    return is;
}
template <typename T1, typename T2>
std::istream& operator>>(std::istream& is, std::pair<T1, T2>& pa) {
    is >> pa.first >> pa.second;
    return is;
}

// Typedefs
#define Pair(typename) std::pair<typename, typename>
#define Vec(typename) std::vector<typename>
#define Arr(typename, count) std::array<typename, count>
#define Vec3(typename) Arr(typename, 3)
typedef long long int s64;
typedef unsigned long long int u64;
typedef signed char s8;
typedef unsigned char u8;
typedef long double ld;

// STL bullshit
// When really want to use, should add std::
#define next nextaerawer
#define prev prevawerawer
#define size sizewaeriwor
#define data dataaeraewra
#define hash hashdesrawer
#define move moveaerawer
#define x0 x0aerawerwe
#define x1 x1aesraewrew
#define y0 y0aeroiawera
#define y1 y1oiiajeroawe
#define left lefteaeraewr
#define right righteaerawer

using namespace std;

// Main segment

vector<int> g[100001] = {};
int d[100001] = {};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int N;
    cin >> N;
    fill(d + 1, d + N + 1, -1);
    for (int i = 1; i < N; i++) {
        int a, b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    priority_queue<pair<int, int>> pq;
    int K;
    cin >> K;
    while (K--) {
        int v, p;
        cin >> v >> p;
        d[v] = p;
        pq.push({-p, v});
    }
    while (!pq.empty()) {
        auto first = pq.top();
        pq.pop();
        for (int to : g[first.second]) {
            if (d[to] == -1) {
                d[to] = -first.first + 1;
                pq.push({-d[to], to});
            }
        }
    }
    for (int i = 1; i <= N; i++)
        for (int to : g[i]) {
            if (abs(d[to] - d[i]) != 1) {
                cout << "No" << endl;
                return 0;
            }
        }
    cout << "Yes" << endl;
    for (int i = 1; i <= N; i++) {
        cout << d[i] << endl;
    }

#ifdef LOCAL
    system("pause");
#endif
    return 0;
}


Measured memory_bytes: 7924