import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextInt()
    val adj = Array(n) { mutableSetOf<Int>() }
    for (i in 0 until n - 1) {
        val v1 = sc.nextInt() - 1
        val v2 = sc.nextInt() - 1
        adj[v1].add(v2)
        adj[v2].add(v1)
    }
    val k = sc.nextInt()
    val p = Array(n) { -1 }
    var first = -1
    for (i in 0 until k) {
        val v = sc.nextInt() - 1
        p[v] = sc.nextInt()
        first = v
    }
    val dist = Array(n) { 0 }
    val que: Queue<Triple<Int, Int, Int>> = ArrayDeque()
    que.add(Triple(first, 0, -1))
    while (que.count() > 0) {
        val (v, step, par) = que.poll()
        dist[v] = step
        for (w in adj[v]) {
            if (w == par) continue
            que.add(Triple(w, step + 1, v))
        }
    }
    val x = p[first]
    val min = Array(n) { -1000000000 }
    val max = Array(n) { 1000000000 }
    for (i in 0 until n) {
        if (p[i] != -1) {
            p[i] = dist[i] + x - p[i]
            min[i] = p[i]
            max[i] = p[i]
            if (p[i] % 2 != 0) {
                ok = false
            }
        }
    }
    if (ok) {
        dfs(adj, first, -1, p, min, max)
    }
    if (ok) {
        paint(adj, first, -1, p, min, max)
    }
    if (ok) {
        println("Yes")
        println((0 until n).map { -p[it] + dist[it] + x }.joinToString("\n"))
    } else {
        println("No")
    }
}

var ok = true

fun dfs(adj:Array<MutableSet<Int>>, v:Int, par:Int, p:Array<Int>, min:Array<Int>, max:Array<Int>) {
    if (p[v] != -1 && par != -1) {
        if (p[v] !in min[par]..max[par] + 2) {
            ok = false
            return
        }
    } else if (par != -1) {
        min[v] = maxOf(min[v], min[par])
        max[v] = minOf(max[v], max[par] + 2)
    }
    for (w in adj[v]) {
        if (w == par) continue
        dfs(adj, w, v, p, min, max)
        min[v] = maxOf(min[v], min[w] - 2)
        max[v] = minOf(max[v], max[w])
    }
    if (min[v] > max[v]) {
        ok = false
    }
}

fun paint(adj:Array<MutableSet<Int>>, v:Int, par:Int, p:Array<Int>, min:Array<Int>, max:Array<Int>) {
    if (par != -1) {
        if (p[par] in min[v]..max[v]) {
            p[v] = p[par]
        } else if (p[par] + 2 in min[v]..max[v]) {
            p[v] = p[par] + 2
        } else {
            ok = false
        }
    }
    for (w in adj[v]) {
        if (w != par) paint(adj, w, v, p, min, max)
    }
}

fun main() = Thread(null, ::main2, "", 64 * 1024 * 1024)
        .apply { setUncaughtExceptionHandler { _, e -> e.printStackTrace(); kotlin.system.exitProcess(1) } }
        .apply { start() }.join()

fun main2() {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}

Measured memory_bytes: 126632