Sweets
Time limit3sMemory limit2048 MB
Given a rooted tree where learning levels grow with each update, find for each day the most markets Sandu can pass on a root-to-k path.
- Level
Hard9 of 10
- Topics
- Tree, Segment tree, Binary search
- Solved
- No attempts yet
Problem
Sandu graduated from high school and decided to pursue his passion as a candy salesperson.
Balti, a city in Moldova, has markets connected by streets. Any market can be reached from any other market by traveling through some streets, and there are exactly streets. Sandu is at market , so the markets form a tree rooted at market .
Each market has a toughness level and a learning level . Initially every learning level is , and Sandu's selling skill level is .
When Sandu visits market , his selling skill level increases by . He succeeds at market if his selling skill level is at least . The skill level increases as soon as he enters market , before he tries to sell anything there.
Each day has an event with two positive integers and . The learning level of market permanently increases by ().
Each day Sandu picks a final market and visits every market on the path from market to market , in that order. He keeps going to whether or not he succeeds. Every day he starts at market with a selling skill level of .
For each day , find the largest number of markets where Sandu can succeed if he picks the final market of that day optimally.
Input
The first line contains two integers and ().
The second line contains integers . There is an edge between and , and is the parent of . It is always true that .
The third line contains integers ().
Each of the next lines contains two integers and (, ) describing the event on day .
Output
Output lines. The -th line contains the answer for day .
Constraints
- for all .
- for all ().
- for all ().
- for all ().