You are given an undirected tree with N nodes. Every node is initially assigned a value equal to 0.
Perform Q queries that are given on the tree as follows:
- u v w: For all the nodes present on a simple path between nodes u and v take the xor of node value with w.
Task
Find the sum of values assigned to all the nodes after performing Q queries.
Input
- First line contains an integer T, denoting the number of test cases.
- For each test case:
- The first line contains two space separated integer N, Q.
- The next N - 1 lines contain two space-separated integers u, v denoting an edge between node u and node v.
- The next Q lines contains three space-separated integers denoting the query.
Output
For each test case in a new line, print the sum of values assigned to each node after performing Q queries.
Constraints
\(1 ≤ T ≤ 5\\ 1 ≤ N, Q ≤ 10^5\\ 0 ≤ w ≤ 10^9\)
1 3 2 1 2 1 3 2 3 5 3 3 5
10
Initial values of the nodes in the tree is \([0,0,0]\).
For \(1^{st}\) Query:
- The simple paths between node \(2\) and \(3\) consists of nodes \([2,1,3]\).
- Value of the nodes will be \([5,5,5]\).
For \(2^{nd}\) Query:
- The simple paths between node \(3\) and \(3\) consists of nodes \([3]\).
- Value of the nodes will be \([5,5,0]\).
Sum of all the nodes in the tree is \(5 +5 = 10\)
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Login to unlock the editorial
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor