Company culture 1

Given each employee's manager and a list of praises, propagate every praise value down the whole subtree and print the total each employee receives.

Medium4TreeDFSPrefix sumGraphInterviewNo attempts yetTime limit2sMemory limit512 MB

Problem

Yeongseon Company has a culture of praise that flows downward. When a manager praises a direct subordinate, that subordinate praises their own direct subordinates, and the praise keeps moving down the chain. So when an employee is praised, every employee below that person receives the same praise.

Every praise carries a number that measures how strong it is. The number is passed down unchanged.

Given the direct manager of each employee and the list of initial praises, compute the total praise value each employee receives.

Input

The first line contains the number of employees nn and the number of initial praises mm. Employees are numbered from 11 to nn. (2n,m1000002 \le n, m \le 100\,000)

The second line contains the direct manager of employees 11 through nn, in order. A manager's number is smaller than the employee's own number. Employee 11 is the president and has no manager, so 1-1 is given for employee 11.

Each of the next mm lines contains an employee number ii who was praised by their direct manager and the praise value ww. (2in2 \le i \le n, 1w10001 \le w \le 1\,000) The same employee may be praised more than once.

The president has no manager, so the president receives no praise.

Output

Print the total praise value of employees 11 through nn on one line, separated by spaces.