#P6504. Problem E. Split The Tree

Problem E. Split The Tree

Problem Description

You are given a tree with n vertices, numbered from 1 to n. ith vertex has a value $w_i$
We define the weight of a tree as the number of different vertex value in the tree.
If we delete one edge in the tree, the tree will split into two trees. The score is the sum of these two trees’ weights.
We want the know the maximal score we can get if we delete the edge optimally

Input

Input is given from Standard Input in the following format:
n
$p_2$ $p_3$ . . . $p_n$
$w_1$ $w_2$ . . . $w_n$
Constraints
2 ≤ n ≤ 100000
1 ≤ $p_i$ < i
1 ≤ $w_i$ ≤ 100000(1 ≤ i ≤ n), and they are integers
$p_i$ means there is a edge between $p_i$ and i

Output

Print one number denotes the maximal score

3 1 1 1 2 2 3 1 1 1 1 1
3 2