Problem:
Score : 800 points

Problem Statement

We have a tree with N vertices. The vertices are numbered 1, 2, ..., N. The i-th (1 ≦ i ≦ N - 1) edge connects the two vertices A_i and B_i.

Takahashi wrote integers into K of the vertices. Specifically, for each 1 ≦ j ≦ K, he wrote the integer P_j into vertex V_j. The remaining vertices are left empty. After that, he got tired and fell asleep.

Then, Aoki appeared. He is trying to surprise Takahashi by writing integers into all empty vertices so that the following condition is satisfied:

Condition: For any two vertices directly connected by an edge, the integers written into these vertices differ by exactly 1.

Determine if it is possible to write integers into all empty vertices so that the condition is satisfied. If the answer is positive, find one specific way to satisfy the condition.

Constraints

1 ≦ N ≦ 10^5

1 ≦ K ≦ N

1 ≦ A_i, B_i ≦ N (1 ≦ i ≦ N - 1)

1 ≦ V_j ≦ N (1 ≦ j ≦ K) (21:18, a mistake in this constraint was corrected)

0 ≦ P_j ≦ 10^5 (1 ≦ j ≦ K)

The given graph is a tree.

All v_j are distinct.

Input

The input is given from Standard Input in the following format:

N
A_1 B_1
A_2 B_2
:
A_{N-1} B_{N-1}
K
V_1 P_1
V_2 P_2
:
V_K P_K

Output

If it is possible to write integers into all empty vertices so that the condition is satisfied, print Yes. Otherwise, print No.

If it is possible to satisfy the condition, print N lines in addition. The v-th (1 ≦ v ≦ N) of these N lines should contain the integer that should be written into vertex v. If there are multiple ways to satisfy the condition, any of those is accepted.

Sample Input 1

5
1 2
3 1
4 3
3 5
2
2 6
5 7

Sample Output 1

Yes
5
6
6
5
7

The figure below shows the tree when Takahashi fell asleep. For each vertex, the integer written beside it represents the index of the vertex, and the integer written into the vertex is the integer written by Takahashi.

Aoki can, for example, satisfy the condition by writing integers into the remaining vertices as follows:

This corresponds to Sample Output 1. Note that other outputs that satisfy the condition will also be accepted, such as:

Yes
7
6
8
7
7

Sample Input 2

5
1 2
3 1
4 3
3 5
3
2 6
4 3
5 7

Sample Output 2

No

Sample Input 3

4
1 2
2 3
3 4
1
1 0

Sample Output 3

Yes
0
-1
-2
-3

The integers written by Aoki may be negative or exceed 10^6.

Solution in Rust (1.15.1) (judge verdict: Runtime Error)

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};
use std::collections::{HashMap, HashSet};

fn main() {
    input!{
        n: usize,
        es: [(usize1, usize1); n - 1],
        k: usize,
        vp: [(usize1, i64); k]
    }
    let mut t = vec![vec![]; n];
    for &(a, b) in &es {
        t[a].push(b);
        t[b].push(a);
    }
    let mut tab = vec![None; n];
    for &(v, p) in &vp {
        tab[v] = Some((p, p + 1));
    }
    dfs(vp[0].0, vp[0].0, &t, &mut tab, vp[0].1 % 2);
    if tab[0].unwrap().0 >= tab[0].unwrap().1 {
        println!("No");
        return;
    }
    println!("Yes");
    let mut ans = vec![0; n];
    ans[vp[0].0] = vp[0].1;
    dfs2(vp[0].0, vp[0].0, &t, &tab, &mut ans);
    for i in 0..n {
        println!("{}", ans[i]);
    }
}

fn dfs(r: usize, p: usize, t: &Vec<Vec<usize>>, tab: &mut Vec<Option<(i64, i64)>>, f: i64) {
    if let Some((a, _)) = tab[r] {
        if a.abs() % 2 != f {
            tab[r] = Some((a, a));
            return;
        }
    }
    let mut range = tab[r];
    for &c in &t[r] {
        if c == p {
            continue;
        }
        dfs(c, r, t, tab, 1 - f);
        if let Some((a, b)) = tab[c] {
            if a >= b {
                tab[r] = tab[c];
                return;
            }
            range = Some(range.map_or((a - 1, b + 1), |x| (max(a - 1, x.0), min(b + 1, x.1))));
        }
    }
    tab[r] = range;
}

fn dfs2(r: usize, p: usize, t: &Vec<Vec<usize>>, tab: &Vec<Option<(i64, i64)>>, v: &mut Vec<i64>) {
    for &c in &t[r] {
        if c == p {
            continue;
        }
        if let Some((a, b)) = tab[c] {
            if a <= v[r] + 1 && v[r] + 1 < b {
                v[c] = v[r] + 1;
            } else {
                v[c] = v[r] - 1;
            }
        } else {
            v[c] = v[r] + 1;
        }
        dfs2(c, r, t, tab, v);
    }
}