Cow Land
Time limit2sMemory limit512 MB
On a weighted tree, support point value updates and path XOR queries between any two nodes, returning the XOR of enjoyment values along the unique route.
- Level
Hard8 of 10
- Topics
- Tree, DFS, Segment tree, Bit manipulation
- Solved
- No attempts yet
Problem
Cow Land is a special amusement park for cows. They roam around, eat delicious grass, and visit the various cow attractions (the roller cowster is especially popular).
There are attractions in total (). Some pairs of attractions are connected by pathways, in total, so that a unique route made up of pathways exists between any two attractions. Attraction has an integer enjoyment value . This value can change over the course of a day, since some attractions are more appealing in the morning and others later in the afternoon.
A cow that travels from attraction to attraction experiences every attraction on the route from to . Curiously, the enjoyment of this entire route is the bitwise XOR of all the enjoyment values along the route, including those of attractions and .
Help the cows determine the enjoyment values of the routes they plan to use on their next trip to Cow Land.
Input
The first line contains and the number of queries (). The next line contains (). The next lines each describe a pathway with two integer attraction IDs and (both in the range ). The last lines each describe either an update to one of the values or a query for the enjoyment of a route. A line of the form "1 " means should be updated to value , and a line of the form "2 " is a query for the enjoyment of the route connecting attractions and .
In test data worth at most 50% of the points, the attraction values never change.
Output
For each query of the form "2 ", print the enjoyment of the route from to on a single line.