output_description: 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.
  
  * * *
input_description: 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
attempt: from heapq import*
  R=range;I=lambda:map(int,input().split());n=int(input());g=[[]for _ in R(n+1)];z=[-1]*n;d=[1e9]*n+[0];q=[-1]*(n+1);r=;Q=[];heappush(Q,(0,-2,n))
  for _ in R(n-1):a,b=I();a-=1;b-=1;g[a]+=[(1,a,b)];g[b]+=[(1,b,a)]
  for _ in R(*I()):a,b=I();a-=1;g[n]+=[(b,n,a)];z[a]=b
  while Q:
  	e=heappop(Q)
  	if q[e[2]]!=-1:continue
  	q[e[2]]=e[1]
  	for f in g[e[2]]:
  		if d[f[2]]>e[0]+f[0]:d[f[2]]=e[0]+f[0];heappush(Q,(e[0]+f[0],f[1],f[2]))
  for _ in g:
  	if any(n!=e[1]and abs(d[e[1]]-d[e[2]])!=1 for e in _):r="No"
  if any(~z[i]and z[i]!=d[i]for i in R(n)):r="No"
  print(r or"Yes\n"+"\n".join(map(str,d[:n])))
problem_description: 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.
samples: [{"input": "5\n    1 2\n    3 1\n    4 3\n    3 5\n    2\n    2 6\n    5 7", "output": "Yes\n    5\n    6\n    6\n    5\n    7\n    \n\nThe figure below shows the tree when Takahashi fell asleep. For each vertex,\nthe integer written beside it represents the index of the vertex, and the\ninteger written into the vertex is the integer written by Takahashi.\n\n![6da26f89839711a520acdf5c3e1cc309.png](https://atcoder.jp/img/arc063/6da26f89839711a520acdf5c3e1cc309.png)\n\nAoki can, for example, satisfy the condition by writing integers into the\nremaining vertices as follows:\n\n![1858d5af5a2c0e51aca39a39d765debb.png](https://atcoder.jp/img/arc063/1858d5af5a2c0e51aca39a39d765debb.png)\n\nThis corresponds to Sample Output 1. Note that other outputs that satisfy the\ncondition will also be accepted, such as:\n\n    \n    \n    Yes\n    7\n    6\n    8\n    7\n    7\n    \n\n* * *"}, {"input": "5\n    1 2\n    3 1\n    4 3\n    3 5\n    3\n    2 6\n    4 3\n    5 7", "output": "No\n    \n\n* * *"}, {"input": "4\n    1 2\n    2 3\n    3 4\n    1\n    1 0", "output": "Yes\n    0\n    -1\n    -2\n    -3\n    \n\nThe integers written by Aoki may be negative or exceed 10^6."}]