{"problem":{"name":"Integers on a Tree","description":{"content":"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 verti","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"arc063_c"},"statements":[{"statement_type":"Markdown","content":"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$.\nTakahashi 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.\nThen, Aoki appeared. He is trying to surprise Takahashi by writing integers into all empty vertices so that the following condition is satisfied:\n\n*   Condition: For any two vertices directly connected by an edge, the integers written into these vertices differ by exactly $1$.\n\nDetermine 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.\n\n## Constraints\n\n*   $1 ≦ N ≦ 10^5$\n*   $1 ≦ K ≦ N$\n*   $1 ≦ A_i, B_i ≦ N$ ($1 ≦ i ≦ N - 1$)\n*   $1 ≦ V_j ≦ N$ ($1 ≦ j ≦ K$) (21:18, a mistake in this constraint was corrected)\n*   $0 ≦ P_j ≦ 10^5$ ($1 ≦ j ≦ K$)\n*   The given graph is a tree.\n*   All $v_j$ are distinct.\n\n## Input\n\nThe input is given from Standard Input in the following format:\n\n$N$\n$A_1$ $B_1$\n$A_2$ $B_2$\n$:$\n$A_{N-1}$ $B_{N-1}$\n$K$\n$V_1$ $P_1$\n$V_2$ $P_2$\n$:$\n$V_K$ $P_K$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"arc063_c","tags":[],"sample_group":[["5\n1 2\n3 1\n4 3\n3 5\n2\n2 6\n5 7","Yes\n5\n6\n6\n5\n7\n\nThe 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.\n\n![image](https://atcoder.jp/img/arc063/6da26f89839711a520acdf5c3e1cc309.png)\n\nAoki can, for example, satisfy the condition by writing integers into the remaining vertices as follows:\n\n![image](https://atcoder.jp/img/arc063/1858d5af5a2c0e51aca39a39d765debb.png)\n\nThis corresponds to Sample Output 1. Note that other outputs that satisfy the condition will also be accepted, such as:\n\nYes\n7\n6\n8\n7\n7"],["5\n1 2\n3 1\n4 3\n3 5\n3\n2 6\n4 3\n5 7","No"],["4\n1 2\n2 3\n3 4\n1\n1 0","Yes\n0\n-1\n-2\n-3\n\nThe integers written by Aoki may be negative or exceed $10^6$."]],"created_at":"2026-03-03 11:01:14"}}