Sweets
시간 제한3초메모리 제한2048 MB
루트가 있는 트리에서 각 시장의 학습 수치가 갱신될 때마다, 루트에서 임의의 노드까지 가는 경로에서 성공할 수 있는 시장 수의 최댓값을 구한다.
문제
Sandu graduated from high school and decided to pursue his passion as a candy salesperson.
Balti, a city in Moldova, has markets, which are connected with streets between them. The marketplace has an interesting structure. Each market can be accessed from any other market by traveling through some number of streets, and there are exactly streets. Also, Sandu is currently staying at market . So, the markets form a rooted tree structure where market is the root.
Additionally, each market has a toughness level and a learning level . Initially the learning level of each market is , and Sandu has a selling skill level of .
When Sandu visits market , his selling skill level increases by . Sandu has success at market if his selling skill level is at least (the market's toughness level). Note that Sandu's selling skill level increases as soon as he enters the market , regardless of whether he was successful or not. This means his selling skill level increases before trying to do anything inside the market.
Also, as Balti is a really busy city, on each of the following days there will be an event happening. On day , event will happen. An event is described by two positive integers - and meaning that on day , there will be an event at the market and the learning level for the corresponding market will be permanently increased by . In other words, event means that on day the learning level will be increased by ().
Sandu plans to visit some markets and sell candies in them. He will pick some market and will visit all markets on the path from the first market to market , in that order. Sandu wants to succeed at as many markets as possible. He will continue his journey towards market regardless of whether he was successful or not. Additionally, every day, Sandu starts at market and his selling skill level resets, starting each day with a selling skill level of .
For each day , help Sandu find the largest number of markets he can be successful at, if he optimally picks the location of the final market of that day.
입력
The first line of input contains two integers and ().
The second line contains integers that represent the rooted tree structure of the markets: , meaning that there exists an edge between and , and is the parent of .
Additionally for each , the condition is always satisfied.
The third line contains integers: () — the toughness level of the given markets.
Then, lines follow, representing the events happening on day .
Line contains two integers — and describing the event for th day (, ).
출력
Output lines - in the -th line you should output the answer for -th day.
제한
- .
- is always satisfied.
- for all ().
- for all ().
- for all ().