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

// Solution for problem: Integers on a Tree

#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 id[100001] = {};
int L[100001] = {}, R[100001] = {};

constexpr int INF = 1e9 + 7;
bool flag = false;

void solve(int v, int fa = -1) {
    L[v] = -INF - 1, R[v] = INF + 1;
    if (id[v] != -1)
        L[v] = R[v] = id[v];
    for (int x : g[v]) {
        if (x == fa)
            continue;
        solve(x, v);
        if (L[x] < -INF / 2)
            continue;
        if (L[v] < -INF / 2) {
            L[v] = L[x] - 1;
            R[v] = R[x] + 1;
        } else {
            if (abs(L[v]) % 2 == abs(L[x]) % 2) {
                flag = true;
                return;
            }
            L[v] = max(L[x] - 1, L[v]);
            R[v] = min(R[x] + 1, R[v]);
        }
    }
    if (L[v] > R[v]) {
        flag = true;
    }
}

void make(int v, int fa = -1) {
    for (int x : g[v]) {
        if (x == fa)
            continue;
        if (L[x] <= id[v] - 1 && id[v] - 1 <= R[x]) {
            id[x] = id[v] - 1;
        } else {
            id[x] = id[v] + 1;
        }
        make(x, v);
    }
}

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

    int N;
    cin >> N;
    fill(id + 1, id + 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);
    }
    int k;
    cin >> k;
    while (k--) {
        int v, p;
        cin >> v >> p;
        id[v] = p;
    }
    solve(1);
    if (flag) {
        cout << "No" << endl;
        return 0;
    }
    id[1] = L[1];
    make(1);
    cout << "Yes" << endl;
    for (int i = 1; i <= N; i++) {
        cout << id[i] << endl;
    }

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


Measured memory_bytes: 13824