#SGM0000079. Truy vấn đường đi từ gốc (Path Queries)
Truy vấn đường đi từ gốc (Path Queries)
Path Queries
Source: CSES
Version: Phuoc Hung OJ Extended
Problem
You are given a tree rooted at vertex 1. Each vertex has a value. Process point assignments and queries asking for the sum of values on the path from the root to a given vertex.
Input
The first line contains and . The second line contains the initial values. The next lines contain the tree edges. Each of the following lines is one of:
1 s x: set the value of vertex to .2 s: query the sum on the path from vertex 1 to vertex .
Output
For each operation of type 2, print the requested path sum.
Subtasks
Subtask 1 (20%)
- The tree size and number of operations are at most 20.
- All other conditions are the same as Subtask 3.
Subtask 2 (30%)
- The tree size and number of operations are at most 2000.
- All other conditions are the same as Subtask 3.
Subtask 3 (50%)
- .
- .
Example
Input
1 9
544
2 1
2 1
1 1 324
1 1 888
2 1
1 1 672
2 1
1 1 6
2 1
Output
544
544
888
672
6
Explanation
Because the tree contains only vertex 1, every path query returns the current value stored at that vertex.