Under construction

Still being built. Things may change

Sweets

Time limit3sMemory limit2048 MB

Summary
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 NN markets connected by streets. Any market can be reached from any other market by traveling through some streets, and there are exactly N−1N - 1 streets. Sandu is at market 11, so the markets form a tree rooted at market 11.

Each market ii has a toughness level tit_i and a learning level lil_i. Initially every learning level is 00, and Sandu's selling skill level is 00.

When Sandu visits market ii, his selling skill level increases by lil_i. He succeeds at market ii if his selling skill level is at least tit_i. The skill level increases as soon as he enters market ii, before he tries to sell anything there.

Each day jj has an event with two positive integers uju_j and xjx_j. The learning level of market uju_j permanently increases by xjx_j (luj:=luj+xjl_{u_j} := l_{u_j} + x_j).

Each day Sandu picks a final market kk and visits every market on the path from market 11 to market kk, in that order. He keeps going to kk whether or not he succeeds. Every day he starts at market 11 with a selling skill level of 00.

For each day jj, 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 NN and QQ (1≤N,Q≤5⋅1051 \le N, Q \le 5 \cdot 10^5).

The second line contains N−1N - 1 integers p2,…,pNp_2, \dots, p_N. There is an edge between pip_i and ii, and pip_i is the parent of ii. It is always true that 1≤pi<i1 \le p_i < i.

The third line contains NN integers t1,t2,…,tNt_1, t_2, \dots, t_N (0≤ti≤1090 \le t_i \le 10^9).

Each of the next QQ lines contains two integers uju_j and xjx_j (1≤uj≤N1 \le u_j \le N, 1≤xj≤1091 \le x_j \le 10^9) describing the event on day jj.

Output

Output QQ lines. The jj-th line contains the answer for day jj.

Constraints

  • 1≤pi<i1 \le p_i < i for all ii.
  • 0≤ti≤1090 \le t_i \le 10^9 for all ii (1≤i≤N1 \le i \le N).
  • 1≤uj≤N1 \le u_j \le N for all jj (1≤j≤Q1 \le j \le Q).
  • 1≤xj≤1091 \le x_j \le 10^9 for all jj (1≤j≤Q1 \le j \le Q).

Examples3

  1. Example 1

    Input
    12 5
    1 1 3 3 1 6 7 1 9 10 11
    1 2 6 3 5 4 6 5 2 3 4 5
    1 1
    1 1
    3 2
    6 3
    9 6
    
    Expected output
    1
    2
    2
    3
    5
    
  2. Example 2

    Input
    5 4
    1 2 3 4
    1 2 5 6 7
    1 1
    1 2
    1 1
    1 2
    
    Expected output
    1
    2
    2
    4
    
  3. Example 3

    Input
    5 5
    1 1 1 1
    1 2 3 4 5
    4 4
    2 2
    5 5
    1 1
    3 3
    
    Expected output
    1
    1
    1
    2
    2