# Maximizing Fun Factor at the Corporate Party
## Problem Statement
In a corporate company, there are $n$ employees, numbered from $1$ to $n$. Person $1$ is the CEO and has no direct boss. Every other person $i$ (where $2 \le i \le n$) has a unique direct boss, denoted as $p_i$. This hierarchy forms a tree structure rooted at the CEO (person $1$).
Each person $i$ in the company has an associated "fun factor" $a_i$. The company is organizing a party, and people decide whether to attend. However, there's a specific social constraint: a person $i$ will not attend the party if their direct boss, $p_i$, is also attending the party. If person $i$'s boss $p_i$ does not attend, then person $i$ is free to choose whether to attend or not.
The goal is to select a subset of people to attend the party such that the total "fun factor" of all attendees is maximized, subject to the given constraint. The total fun factor is the sum of $a_i$ for all people $i$ who attend the party.
## Input Format
The input consists of three lines:
- The first line contains a single integer $n$ ($1 \le n \le 10^5$), representing the number of people in the company.
- The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^9 \le a_i \le 10^9$), where $a_i$ is the fun factor of person $i$.
- The third line contains $n-1$ integers $p_2, p_3, \dots, p_n$ ($1 \le p_i \le n$, $p_i \ne i$), where $p_i$ is the direct boss of person $i$. It is guaranteed that $p_i$ will always refer to a valid existing person in the company, and the boss-subordinate relationships form a valid tree structure rooted at person $1$.
## Output Format
Output a single integer, the maximum possible total fun factor for the party.
## Sample Test Cases
### Sample Input 1
```
3
10 20 30
1 1
```
### Sample Output 1
```
50
```
### Sample Input 2
```
4
10 5 100 1
1 2 2
```
### Sample Output 2
```
111
```
## Constraints
- $1 \le n \le 10^5$
- $-10^9 \le a_i \le 10^9$
- $1 \le p_i \le n$, for $2 \le i \le n$
- $p_i \ne i$ for all $i$
- The given boss structure forms a tree rooted at person $1$.
- Time limit: 1 second
- Memory limit: 256 MB
## Explanation
### Sample 1:
- $n=3$, fun factors $a = [10, 20, 30]$.
- Bosses: $p_2=1$, $p_3=1$. This means person 1 is the boss of both person 2 and person 3.
- The hierarchy is:
```
1 (fun=10)
/ \
2(fun=20) 3(fun=30)
```
- Possible attendance scenarios:
1. Person 1 attends: Fun factor $+10$. Persons 2 and 3 cannot attend (boss is present). Total fun $= 10$.
2. Person 1 does not attend:
* Person 2 can attend: Fun factor $+20$.
* Person 3 can attend: Fun factor $+30$.
Total fun $= 20 + 30 = 50$.
- The maximum fun factor is $\max(10, 50) = 50$.
Loading problem statement...