Codeforces Round 851 (Div. 2)
F
XOR, Tree, and Queries
Codeforces
2500
原题
← E→
翻译中…

You are given a tree of $n$ vertices. The vertices are numbered from $1$ to $n$.

翻译中…

You will need to assign a weight to each edge. Let the weight of the $i$-th edge be $a_i$ ($1 \leq i \leq n-1$). The weight of each edge should be an integer between $0$ and $2^{30}-1$, inclusive.

翻译中…

You are given $q$ conditions. Each condition consists of three integers $u$, $v$, and $x$. This means that the bitwise XOR of all edges on the shortest path from $u$ to $v$ should be $x$.

翻译中…

Find out if there exist $a_1, a_2, \ldots, a_{n-1}$ that satisfy the given conditions. If yes, print a solution such that $a_1 \oplus a_2 \oplus \ldots \oplus a_{n-1}$ is the smallest. Here, $\oplus$ denotes the bitwise XOR operation.

翻译中…

If there are multiple solutions such that $a_1 \oplus a_2 \oplus \ldots \oplus a_{n-1}$ is the smallest, print any.

翻译中…

Input

翻译中…

The first line contains two integers $n$ and $q$ ($2 \le n \le 2.5 \cdot 10^5$, $0 \le q \le 2.5 \cdot 10^5$).

翻译中…

The $i$-th of the following $n-1$ lines contains two integers $x_i$ and $y_i$ ($1 \le x_i, y_i \le n$, $x_i \neq y_i$), meaning that the $i$-th edge connects vertices $x_i$ and $y_i$ in the tree.

翻译中…

It is guaranteed that the given edges form a tree.

翻译中…

The following $q$ lines contain information about conditions.

翻译中…

Each line contains three integers $u$, $v$, $x$ ($1 \le u, v \le n$, $u \neq v$, $0 \le x \le 2^{30}-1$), meaning that the bitwise XOR of all edges on the shortest path from $u$ to $v$ should be $x$.

翻译中…

Output

翻译中…

If there do not exist $a_1$, $a_2$, ..., $a_{n-1}$ that satisfy the given conditions, print "No".

翻译中…

Otherwise, print "Yes" in the first line.

翻译中…

Then print $n-1$ integers on the next line, where the $i$-th integer is the weight of the $i$-th edge. If there are multiple solutions that satisfy the given conditions, print a solution such that $a_1 \oplus a_2 \oplus \ldots \oplus a_{n-1}$ is the smallest.

翻译中…

If there are multiple solutions such that $a_1 \oplus a_2 \oplus \ldots \oplus a_{n-1}$ is the smallest, print any.

翻译中…

When printing "Yes" or "No", you can print each letter in any case (either upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.

翻译中…

Note

翻译中…

For the first example, there does not exist a set of edge weights that satisfies the given conditions.

翻译中…

For the second example, the two given conditions are $a_1 \oplus a_2 \oplus a_3=2$ and $a_4 \oplus a_5=7$. There can be multiple solutions, for example, $(a_1, a_2, a_3, a_4, a_5)=(1, 2, 1, 4, 3)$.

翻译中…

For the third example, the two given conditions are $a_1 \oplus a_2 \oplus a_3=3$ and $a_1 \oplus a_4 \oplus a_5=5$. There are multiple solutions that satisfy the given conditions.

翻译中…

$(a_1, a_2, a_3, a_4, a_5)=(1, 1, 3, 4, 0)$ satisfies the given conditions, but the bitwise XOR of all edge weights is $7$, which does not have the smallest $a_1 \oplus a_2 \oplus \ldots \oplus a_{n-1}$, so it cannot be the answer.

翻译中…

样例

Input #1
4 4
1 2
2 3
3 4
1 4 3
2 4 2
1 3 1
2 3 1
Output #1
No
InputCopy OutputCopy
Input #2
6 2
1 2
2 3
3 4
2 5
5 6
1 4 2
2 6 7
Output #2
Yes
4 2 4 1 6
InputCopy OutputCopy
Input #3
6 2
1 2
2 3
3 4
2 5
5 6
1 4 3
1 6 5
Output #3
Yes
6 1 4 3 0
InputCopy OutputCopy
题目信息
题号
1788F
时间限制
3 s
内存限制
256 MB
标签
位运算
构造
DFS 及类似
并查集
图论
贪心
模拟
树

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。