|
||||||||||
Problem E. Split The TreeTime Limit: 7000/4000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 929 Accepted Submission(s): 270 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 Sample Input
Sample Output
Source | ||||||||||
|