You are given a company with $$$n$$$ employees, numbered from $$$1$$$ to $$$n$$$. The company follows a hierarchical structure such that every employee (except the CEO) has exactly one direct boss. The CEO (employee $$$1$$$) does not report to anyone.
Each employee generates a certain profit (or loss) for the company. You are given the profit/loss value for each employee.
For any employee $$$x$$$, define their team as:
The total profit of a team is the sum of profit/loss values of all employees in the team.
Your task is to determine the maximum profit among all such teams in the company.
The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the number of employees in the company.
The second line contains $$$n - 1$$$ integers $$$p_2, p_3, \ldots, p_n$$$ ($$$1 \leq p_i \leq n$$$), where $$$p_i$$$ denotes the direct boss of employee $$$i$$$.
The third line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-200 \leq a_i \leq 200$$$), where $$$a_i$$$ represents the profit/loss value of employee $$$i$$$.
Print a single integer — the maximum profit made by any team.
Input:
5 1 1 2 3 5 -2 3 4 -1
Output:
9
Explanation of the sample test.
We are given:
This represents the following company hierarchy:
Now, we compute the total profit for each team (i.e., the subtree sum rooted at each employee):
The maximum profit among all teams is $$$\boxed{9}$$$.