Increasing Values

3.2

5 votes
Sparse Table, Tree, Data Structures, Medium-Hard, Loops, Segment tree
Problem

You are given a tree of N nodes. The tree is rooted at vertex 1. Every node of the tree is assigned a value. Lets denote the value of the ith node by fi. We call a node good if the sum of values of all nodes in its subtree is strictly greater than X.

You have to perform Q update operations on this tree. In each update you have to increase the value of some node. After each update print the number of good nodes.

Input Format

The first line of input contains three integers N, Q and X.

Each of the next N1 lines contain two integers ui and vi - indices of vertices, connected by the i-th edge. It's guaranteed that given graph is a tree.

The next line contains N integers, the ith denoting fi.

The next Q lines contain two integers di and ai denoting that ai is added to the node di.

Output Format

Output Q integers - the number of good nodes after the each update.

Constraints

1N,Q105
1ui,vi,diN
1X,ai,fi109

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Initially 1 is the only good node.

In the first update we add 5 to node 2, which makes 2 a good node. The good nodes after 1st update are - 1,2.

Next, we add 1 to node 4, but it doesn't add any new good nodes.

In the last update, we add 1 to node 3. Now 3 is also a good node and there are 3 good nodes - 1,2,3.

Editor Image

?