CF1788F.XOR, Tree, and Queries

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a tree of nn vertices. The vertices are numbered from 11 to nn .

You will need to assign a weight to each edge. Let the weight of the ii -th edge be aia_i ( 1in11 \leq i \leq n-1 ). The weight of each edge should be an integer between 00 and 23012^{30}-1 , inclusive.

You are given qq conditions. Each condition consists of three integers uu , vv , and xx . This means that the bitwise XOR of all edges on the shortest path from uu to vv should be xx .

Find out if there exist a1,a2,,an1a_1, a_2, \ldots, a_{n-1} that satisfy the given conditions. If yes, print a solution such that a1a2an1a_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 a1a2an1a_1 \oplus a_2 \oplus \ldots \oplus a_{n-1} is the smallest, print any.

输入格式

The first line contains two integers nn and qq ( 2n2.51052 \le n \le 2.5 \cdot 10^5 , 0q2.51050 \le q \le 2.5 \cdot 10^5 ).

The ii -th of the following n1n-1 lines contains two integers xix_i and yiy_i ( 1xi,yin1 \le x_i, y_i \le n , xiyix_i \neq y_i ), meaning that the ii -th edge connects vertices xix_i and yiy_i in the tree.

It is guaranteed that the given edges form a tree.

The following qq lines contain information about conditions.

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

输出格式

If there do not exist a1a_1 , a2a_2 , ..., an1a_{n-1} that satisfy the given conditions, print "No".

Otherwise, print "Yes" in the first line.

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

If there are multiple solutions such that a1a2an1a_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.

输入输出样例

  • 输入#1

    4 4
    1 2
    2 3
    3 4
    1 4 3
    2 4 2
    1 3 1
    2 3 1

    输出#1

    No
  • 输入#2

    6 2
    1 2
    2 3
    3 4
    2 5
    5 6
    1 4 2
    2 6 7

    输出#2

    Yes
    4 2 4 1 6
  • 输入#3

    6 2
    1 2
    2 3
    3 4
    2 5
    5 6
    1 4 3
    1 6 5

    输出#3

    Yes
    6 1 4 3 0

说明/提示

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 a1a2a3=2a_1 \oplus a_2 \oplus a_3=2 and a4a5=7a_4 \oplus a_5=7 . There can be multiple solutions, for example, (a1,a2,a3,a4,a5)=(1,2,1,4,3)(a_1, a_2, a_3, a_4, a_5)=(1, 2, 1, 4, 3) .

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

(a1,a2,a3,a4,a5)=(1,1,3,4,0)(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 77 , which does not have the smallest a1a2an1a_1 \oplus a_2 \oplus \ldots \oplus a_{n-1} , so it cannot be the answer.

首页