Mexor tree
Time limit2sMemory limit1024 MB
Given a tree with path-XOR updates, find for each vertex the smallest non-negative integer missing from the values on its path from S after all updates.
- Level
Medium7 of 10
- Topics
- Tree, Segment tree, DFS, Bit manipulation
- Solved
- No attempts yet
Problem
A tree with vertices is given. Vertex has value .
There are queries in total.
- : Replace each value on the simple path between vertices and with the result of XOR-ing it with .
After performing all queries, define a new sequence as follows.
- is the smallest non-negative integer that does not appear among the values on the simple path between vertex and vertex .
Find all .
Input
The first line contains integers and separated by a space.
The second line contains the sequence separated by spaces.
From the third line, the next lines each contain two integers separated by a space, meaning there is an edge between vertex and vertex .
Line contains the number of queries .
From line , the next lines each contain three integers separated by spaces.
Output
Print the sequence separated by spaces on the first line.