XOR in Tree
Practice
4.2 (6 votes)
Approved
Data structures
Fenwick tree
Medium
Open
Trees
Problem
37% Success 711 Attempts 30 Points 3s Time Limit 256MB Memory 1024 KB Max Code

In Graph theory, tree is a simple connected acyclic graph. You are given a tree consists of N nodes numbered from 1 to N. Each node i have a value Ai associated with it. Your task is writing a program doing Q operations, each operations is 1 of 2 following types:

  1. u, v: Assign Au to v.
  2. u, v: Calculate XOR sum of all value associated with nodes in unique single path from u to v.

Input

The first line is T - the number of test cases. Then T test cases follow.

Each test consists of several lines.

  • The first line contains a single integer N - the number of nodes in tree.
  • The second line contains N integers A1, A2, .., AN where Ai is value associated with node i.
  • Then N - 1 lines, each line contains two integer u and v (1 ≤ u, vN) denoting there is a direct edge between node u and node v. It is guaranteed that these edges form a tree.
  • Then Q in a single line - the number of operations.
  • Q lines follow, each line contains 3 integer t, u, v in which t is 1 or 2 denoting type of this operation described in the statement. If t = 1 then 1 ≤ uN, 1 ≤ v ≤ 109. If t = 2 then 1 ≤ u, vN.

Output

For each operations of type 2, print the answer in a single line.

Constraints

  • 1 ≤ T ≤ 10
  • 1 ≤ N ≤ 105
  • 1 ≤ Ai ≤ 109
  • 1 ≤ Q ≤ 105

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

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
18 votes
Tags:
Advanced Data StructuresData StructuresMediumSegment Trees
Points:30
9 votes
Tags:
Advanced Data StructuresData StructuresGCDImplementationNumber theorySegment Trees
Points:30
17 votes
Tags:
CombinatoricsData StructuresMathMediumSegment TreesTrees