James' XOR Update

View as PDF

Submit solution


Points: 12 (partial)
Time limit: 1.0s
Memory limit: 128M

Author:
Problem type

You are given a tree with N nodes, with each node assigned a value vi. Support the following update:

  • a b x XOR every other node on the path from a to b by x. (update node a, 3rd node on path a to b, 5th node on path a to b).

After all the updates, output the value of each node.

Input Specification

The first line of input contains N, and the number of updates Q.

The next line contains N space-separated integers, v1,v2,,vN.

The next N1 lines contain two space-separated integers, xi yi, describing an edge connecting nodes xi and yi.

The next Q lines contain three space-separated integers, ai bi ci, describing an update.

Output Specification

Output one line containing N space-separated integers, the final value of node 1,2,,N.

Constraints

1ai,bi,xi,yiN

1ci,vi106

Subtask 1 [20%]

1N,Q1000

Subtask 2 [80%]

1N200000

1Q100000

Sample Input

Copy
7 2
0 0 0 0 0 0 0
1 2
2 3
3 4
1 5
5 6
6 7
4 7 2
3 6 3

Sample Output

Copy
3 2 3 2 2 3 2

Comments

There are no comments at the moment.