import scala.collection.mutable.PriorityQueue
import java.util.Scanner

object Main extends App{
  val sc = new Scanner(System.in)

  // (cost, node)
  val q = new PriorityQueue[(Int, Int)]  

  val n = sc.nextInt()
  val tree: Array[List[Int]] = Array.fill(n+1)(List())
  val paint: Array[Option[Int]] = Array.fill(n+1)(None)

  for(i <- 1 to n-1){
    val a = sc.nextInt(); val b = sc.nextInt()
    tree(a) = b :: tree(a)
    tree(b) = a :: tree(b)
  }

  var start = -1
  val k = sc.nextInt()
  for(i <- 1 to k){
    val v = sc.nextInt(); val p = sc.nextInt()
    paint(v) = Some(p)
    q += ((p, v))
    start = v
  }


  ////
  // painting
  while(!q.isEmpty){
    val (cost, node) = q.dequeue

    for(e <- tree(node)){
      paint(e) match{
        case Some(_) => ()
        case None =>
          paint(e) = Some(cost - 1)
          q += ((cost-1, e))
      }
    }
  }

  var ansflag = true
  val break = new scala.util.control.Breaks
  // (node, cost, preNode)
  val dfs = new scala.collection.mutable.Stack[(Int, Int, Int)]
  dfs.push((1, paint(1).get, 1))

  break.breakable{
    while(!dfs.isEmpty){
      val (node, cost, preNode) = dfs.pop
      for(e <- tree(node)){
        if(e != preNode){
          paint(e) match{
            case Some(x) =>
              if((x-cost).abs == 1){
                dfs.push((e, x, node))
              }
              else{
                ansflag = false
                break.break
              }
            case None => throw new Exception("error")
          }
        }
      }
    }
  }

  if(ansflag){
    println("Yes")
    for(i <- 1 to n)
      println(paint(i).get)
  }
  else
    println("No")
}
