#include <iterator>
#include <cstdio>
#include <array>
#include <vector>
#include <functional>
#include <map>
namespace XX
{   
    template<template<typename> class Compare, typename T>
    inline T& UP(T& x, const T& y){if(Compare<T>()(y, x)) x = y; return x;}
    template<typename Compare, typename T>
    inline T& UP(T& x, const T& y, Compare comp){if(comp(y, x)) x = y; return x;}

    template<typename T> inline T& GT(T& x, const T& y){return UP<std::greater>(x, y);}
    template<typename T> inline T& LS(T& x, const T& y){return UP<std::less>(x, y);}

    template<typename T>
    struct Mapper
    {
        int operator[](const T& v) { int& ret = table[v]; if(!ret) rtable[ret = table.size()] = v; return ret - 1; }
        template<typename... Args> int operator()(Args... args) { return (*this)[T(args...)]; }
        T rev(int idx){return rtable[idx + 1];}
        std::map<T, int> table;
        std::map<int, T> rtable;
    };

    template<typename T, int S>
    struct ReferenceArray
    {
        struct It {typename std::array<T*, S>::iterator it; T& operator*(){return **it;} void operator++(){it++;} bool operator!=(const It& other){return it != other.it;} };
        int size()const{return _ptr.size();}
        It begin()const{return {_ptr.begin()};}
        It end()const{return {_ptr.end()};}
        T& operator[](int idx)const{return *_ptr[idx];}
        mutable std::array<T*, S> _ptr;
    };
    template<typename T, typename... Args> 
    ReferenceArray<T, sizeof...(Args) + 1> MAKEV(T& arg1, Args&... args) {return {&arg1, &args...};}

    struct Range
    {   
        struct It {   int num, step; int operator*(){return num;} void operator++(){num += step;} bool operator!=(const It& other){return num != other.num;} };
        Range(int ee):b(0),e(ee){}
        Range(int bb, int ee):b(bb), e(ee){}
        It begin(){return {b, (b < e? 1: -1)};}
        It end(){return {e, 0};}
        int b, e;
    };

}



template<typename T> struct ScanfSpecifier{};
#define DEF(T,V) template<> struct ScanfSpecifier<T>{static constexpr const char* value = V;};
DEF(char*,"%s")DEF(int,"%d")DEF(double,"%lf")DEF(float,"%f")DEF(char,"%c")DEF(const char*,"%s")DEF(unsigned long,"%lu")DEF(unsigned int, "%u")
#ifdef _MSC_VER
DEF(long long int,"%I64d")
#else
DEF(long long int,"%lld")
#endif
#undef DEF
template<typename T> int RD(T& arg){return std::scanf(ScanfSpecifier<T>::value, &arg);}
template<int S> int RD(char (&arg)[S]){return std::scanf("%s", arg);}
int RD(char* arg){return std::scanf("%s", arg);}
template<> int RD<char>(char& arg){return std::scanf(" %c", &arg);}
template<typename T, typename... Args> int RD(T& arg1, Args&... args) {return RD(arg1) + RD(args...);}
template<typename T> T RD(){T ret; RD(ret); return ret;}
template<typename It> void RDV(It begin, It end) { while(begin != end) RD(*begin++); }
template<typename C> void RDV(C& c) {RDV(std::begin(c), std::end(c));}
template<typename... Args> void WT(Args... args) { int alc = 0; int dummy[] = {((alc++? std::printf(" "): 0), std::printf(ScanfSpecifier<Args>::value, args), 0)...}; }
template<typename... Args> void WTL(Args... args) { WT(args...); std::printf("\n"); }
template<typename It> void WTV(It begin, It end) { int alc = 0; while(begin != end) (alc++? std::printf(" "): 0), WT(*begin++); }
template<typename C> void WTV(const C& c) {WTV(std::begin(c), std::end(c));}
template<typename It> void WTVL(It begin, It end) { WTV(begin, end); std::printf("\n"); }
template<typename C> void WTVL(const C& c) {WTVL(std::begin(c), std::end(c));}





//alias
//RD[L],RDV[L],WT[L],WTV[L] for i/o
template<typename T> T& UMAX(T& x, T y){return XX::UP<std::greater>(x, y);}
template<typename T> T& UMIN(T& x, T y){return XX::UP<std::less>(x, y);}
using XX::UP; //(x,y) comp
using RG = XX::Range;
using XX::MAKEV;
using XX::Mapper;
//template
#include <vector>
#include <string>
#include <set>
#include <map>
#include <cstdlib>
#include <algorithm>
#include <functional>
using namespace std;

const int SIZE = 100009;
vector<int> adj[100009];

bool paint[100009];
bool leaf[SIZE];
int value[100009];

int mn[SIZE];
int mx[SIZE];


void dfs(int u, int p)
{
    if(paint[u])
    {
        leaf[u] = true;
        mn[u] = mx[u] = value[u];
    }
    for(int to: adj[u])
        if(to != p)
        {
            dfs(to, u);
            if(leaf[to])
            {
                if(!leaf[u])
                {
                    mn[u] = mn[to] - 1, mx[u] = mx[to] + 1;
                    leaf[u] = true;
                }
                else 
                {
                    UMAX(mn[u], mn[to] - 1);
                    UMIN(mx[u], mx[to] + 1);
                }
            }
        }
}


bool ans = true;

void dfs2(int u, int p)
{
    if(leaf[u] && (value[u] < mn[u] || value[u] > mx[u]))
    {
        ans = false;
        return;
    }

    for(int to: adj[u])
        if(to != p)
        {
            if(paint[to])
            {
                if(abs(value[u] - value[to]) != 1)
                {
                    ans = false;
                    return;
                }
                else
                {
                    dfs2(to, u);
                }
            }
            else if(leaf[to] && value[u] > mx[to])
            {
                value[to] = value[u] - 1;
                dfs2(to, u);
            }
            else
            {
                value[to] = value[u] + 1;
                dfs2(to, u);
            }
        }
}

int main()
{
    int N, K;
    RD(N);
    for(int i: RG(N - 1))
    {
        int a, b;
        RD(a, b);
        a--, b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    RD(K);

    int root, shift;
    for(int i: RG(K))
    {
        int u, p;
        RD(u, p);

        u--;
        
        if(!i)
        {
            root = u;
            shift = p;
        }

        paint[u] = true;
        value[u] = p - shift;
    }

    dfs(root, -1);
    dfs2(root, -1);


    if(!ans)
        WTL("No");
    else
    {
        WTL("Yes");
        for(int i: RG(N))
            WTL(value[i] + shift);
    }

}





Measured memory_bytes: 13952