#P10799. Triangle Formation on a Tree
Triangle Formation on a Tree
Triangle Formation on a Tree
You are given a tree with (n) nodes numbered (1 \sim n). Each node (i) initially has a weight (a_i). There are (q) operations, which are of two types:
-
Update Operation: Given integers (x), (y), and (k), perform an update on the simple path from (x) to (y) by applying the bitwise XOR with (k) to each node's weight along this path. Formally, for every node (i) on the simple path from (x) to (y), update (a_i := a_i \oplus k).
-
Query Operation: Given integers (x) and (y), determine whether it is possible to select three different nodes on the simple path from (x) to (y) such that their current weights can serve as the side lengths of a non-degenerate triangle. A triangle is non-degenerate if for three sides (a), (b), and (c) the following conditions hold:
[ a+b>c,\quad b+c>a,\quad c+a>b ]
If there are fewer than three nodes on the path or no valid triple exists, the answer is considered "No".
It is guaranteed that at any moment, no node will have a weight equal to (0).
inputFormat
The input begins with a line containing two integers (n) and (q).
The second line contains (n) integers (a_1, a_2, \ldots, a_n) representing the initial weights of the nodes.
The following (n-1) lines each contain two integers (u) and (v), representing an undirected edge between nodes (u) and (v).
Each of the next (q) lines describes an operation in one of the two formats below:
\
- Update Operation: “1 x y k”\
- Query Operation: “2 x y”
outputFormat
For each query operation (operation of type 2), output a single line containing "Yes" if it is possible to form a triangle with three distinct nodes' weights on the path from (x) to (y), or "No" otherwise.
sample
5 4
1 2 3 4 5
1 2
2 3
3 4
4 5
2 1 5
1 2 4 1
2 1 5
1 1 3 4
2 1 5
Yes
Yes
Yes
</p>