macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; ( iter = $ iter : ident , $ ( $ r : tt ) * ) => { let s = { use std :: io :: Read ; let mut s = String :: new ( ) ; std :: io :: stdin ( ) . read_to_string ( & mut s ) . unwrap ( ) ; s } ; let mut $ iter = s . split_whitespace ( ) ; input_inner ! { $ iter , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let s = { use std :: io :: Read ; let mut s = String :: new ( ) ; std :: io :: stdin ( ) . read_to_string ( & mut s ) . unwrap ( ) ; s } ; let mut iter = s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; }
macro_rules ! input_inner { ( $ iter : expr ) => { } ; ( $ iter : expr , ) => { } ; ( $ iter : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , mut $ var : ident $ ( $ r : tt ) * ) => { input_inner ! { $ iter , mut $ var : usize $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident $ ( $ r : tt ) * ) => { input_inner ! { $ iter , $ var : usize $ ( $ r ) * } } ; }
macro_rules ! read_value { ( $ iter : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ iter , $ t ) ) ,* ) } ; ( $ iter : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ iter , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ iter : expr , { chars : $ base : expr } ) => { read_value ! ( $ iter , String ) . chars ( ) . map ( | c | ( c as u8 - $ base as u8 ) as usize ) . collect ::< Vec < usize >> ( ) } ; ( $ iter : expr , { char : $ base : expr } ) => { read_value ! ( $ iter , { chars : $ base } ) [ 0 ] } ; ( $ iter : expr , chars ) => { read_value ! ( $ iter , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ iter : expr , char ) => { read_value ! ( $ iter , chars ) [ 0 ] } ; ( $ iter : expr , usize1 ) => { read_value ! ( $ iter , usize ) - 1 } ; ( $ iter : expr , $ t : ty ) => { $ iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) } ; }
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct Adjacent {
    pub to: usize,
    pub id: usize,
}
impl Adjacent {
    pub fn new(to: usize, id: usize) -> Adjacent {
        Adjacent { to: to, id: id }
    }
}
#[derive(Clone, Debug, Default)]
pub struct Graph {
    pub vsize: usize,
    pub esize: usize,
    pub graph: Vec<Vec<Adjacent>>,
}
impl Graph {
    pub fn new(vsize: usize) -> Graph {
        Graph {
            vsize: vsize,
            esize: 0,
            graph: vec![vec![]; vsize],
        }
    }
    pub fn add_edge(&mut self, from: usize, to: usize) {
        self.graph[from].push(Adjacent::new(to, self.esize));
        self.esize += 1;
    }
    pub fn add_undirected_edge(&mut self, u: usize, v: usize) {
        self.graph[u].push(Adjacent::new(v, self.esize));
        self.graph[v].push(Adjacent::new(u, self.esize));
        self.esize += 1;
    }
    pub fn vertexes(&self) -> std::ops::Range<usize> {
        0..self.vsize
    }
    pub fn adjacency(&self, from: usize) -> &Vec<Adjacent> {
        &self.graph[from]
    }
}
#[derive(Debug)]
pub struct TreeRec {
    pub n: usize,
    pub lb: Vec<i64>,
    pub ub: Vec<i64>,
}
impl TreeRec {
    pub fn new(n: usize, vp: Vec<(usize, i64)>) -> TreeRec {
        let mut lb = vec![-1_001_001_001; n];
        let mut ub = vec![1_001_001_001; n];
        for &(v, p) in &vp {
            lb[v] = p;
            ub[v] = p;
        }
        TreeRec {
            n: n,
            lb: lb,
            ub: ub,
        }
    }
    pub fn dfs(&mut self, u: usize, p: usize, graph: &Graph) {
        for v in graph.adjacency(u) {
            if v.to != p {
                self.lb[u] = max(self.lb[u], self.lb[v.to] - 1);
                self.ub[u] = min(self.ub[u], self.ub[v.to] + 1);
                self.lb[v.to] = max(self.lb[v.to], self.lb[u] - 1);
                self.ub[v.to] = min(self.ub[v.to], self.ub[u] + 1);
                self.dfs(v.to, u, graph);
                self.lb[u] = max(self.lb[u], self.lb[v.to] - 1);
                self.ub[u] = min(self.ub[u], self.ub[v.to] + 1);
                self.lb[v.to] = max(self.lb[v.to], self.lb[u] - 1);
                self.ub[v.to] = min(self.ub[v.to], self.ub[u] + 1);
            }
        }
        if p < self.n {
            self.lb[u] = max(self.lb[u], self.lb[p] - 1);
            self.lb[p] = max(self.lb[p], self.lb[u] - 1);
            self.ub[u] = min(self.ub[u], self.ub[p] + 1);
            self.ub[p] = min(self.ub[p], self.ub[u] + 1);
        }
    }
}
use std::cmp::{max, min};
fn main() {
    input! { n, ab: [(usize1, usize1); n-1], k, vp: [(usize1, i64); k] };
    let mut g = Graph::new(n);
    let u = vp[0].0;
    let mut r = TreeRec::new(n, vp);
    for &(a, b) in &ab {
        g.add_undirected_edge(a, b);
    }
    r.dfs(u, n, &g);
    r.dfs(u, n, &g);
    if (0..n).all(|i| r.ub[i] >= r.lb[i] && (r.ub[i] - r.lb[i]) % 2 == 0) {
        println!("Yes");
        for i in 0..n {
            println!("{}", r.lb[i]);
        }
    } else {
        println!("No");
    }
}


Measured memory_bytes: 25596