#P6018. [Ynoi2010] Fusion tree
[Ynoi2010] Fusion tree
Problem Description
There is a big tree in a magic forest, and children often hold gatherings under it.
The tree can be seen as an undirected connected graph with nodes and edges. Each node of the tree has some bottles of mineral water. Initially, node has bottles.
Majies lives at the top of the tree. One day, he wants to remodel the tree so that it will be convenient for him to sort the empty mineral water bottles for recycling after he drinks a lot of water.
Majies likes binary operations, so he will perform the following three types of operations:
- Add to the number of mineral water bottles on every node whose distance to a node is . The distance between two nodes on the tree is defined as the number of edges on the shortest path between them.
- Drink bottles of water at node .
- Query the xor sum of the numbers of mineral water bottles on all nodes whose distance to a node is .
Majies has operations in total. You need to output the answer after each operation of type .
Input Format
The first line contains two positive integers , which represent the number of nodes in the tree and the number of queries.
Lines to each contain two integers, indicating an edge connecting these two nodes.
Line contains integers. The -th integer indicates the initial number of mineral water bottles at node .
Lines to each start with an integer representing the operation type.
If or , then an integer follows, indicating the node that Majies operates on.
Otherwise, two integers follow, indicating the node that Majies operates on and the number of bottles he drinks.
Output Format
For each operation of type , output one line containing one integer, which is the answer.
3 2
1 2
2 3
1 1 4
1 1
3 2
5
Hint
Idea: dangxingyu, Solution: dangxingyu, Code: dangxingyu, Data: dangxingyu.
For of the testdata, , .
For of the testdata, , .
For another of the testdata, there exists a node such that the distance from every node to this node is .
For of the testdata, , , , , .
It is guaranteed that the number of mineral water bottles at each node is non-negative at any time.
Friendly reminder: mineral water bottles are neither dry waste nor wet waste; they are recyclable waste.
Translated by ChatGPT 5