7448: Count on a Tree II Striking Back

内存限制:128 MB 时间限制:1 S
题面:传统 评测方式:文本比较 上传者:
提交:0 通过:0

题目描述

You are given a tree with n nodes. The tree nodes are numbered from 1 to n. The color of the i-th node
is coli.
You need to perform the following operations for m times:
• “1 x y” (1 ≤ x, y ≤ n): Change the color of the x-th node into y.
• “2 a b c d” (1 ≤ a, b, c, d ≤ n): Let’s denote f(u, v) as the number of difffferent colors occured on
the path from u to v. You need to answer whether f(a, b) > f(c, d) is true.

输入格式

The fifirst line of the input contains a single integer T (1 ≤ T ≤ 4), the number of test cases.
For each case, the fifirst line of the input contains two integers n and m (1 ≤ n ≤ 500 000, 1 ≤ m ≤ 10 000),
denoting the number of nodes and the number of operations.
The second line of the input contains n integers col1, col2, . . . , coln (1 ≤ coli ≤ n), denoting the initial
color of each node.
Each of the following n n 1 lines contains two integers ui and vi (1 ≤ ui , vi ≤ n, ui = vi), denoting an
bidirectional edge between the ui-th node and the vi-th node.
Each of the next m lines describes an operation in formats described in the statement above, except that
some parameters are encrypted in order to enforce online processing.
Let cnt be the number of queries that you answered “Yes” before in this test case. Note that cnt should
be reset to 0 in each new test case. For each operation, x, y, a, b, c and d are encrypted. The actual values
of x, y, a, b, c and d are x ⊕ cnt, y ⊕ cnt, a ⊕ cnt, b ⊕ cnt, c ⊕ cnt and d ⊕ cnt. In the expressions above, the
symbol “⊕” denotes the bitwise exclusive-or operation. Also note that the constraints described in the
statement above apply to the corresponding parameters only after decryption, the encrypted values are
not subject to those constraints.
It is guaranteed that f(a, b) ≥ 2f(c, d) or f(c, d) ≥ 2f(a, b) always holds for each query

输出格式

For each query, print a single line. If f(a, b) > f(c, d) is true, print “Yes” else print “No”.

输入样例 复制

1
8 4
1 2 1 4 1 3 3 2
1 2
2 3
3 4
3 5
1 6
6 7
6 8
2 1 4 3 5
2 7 6 5 9
1 4 9
2 2 4 7 6

输出样例 复制

Yes
No
Yes

分类标签