当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

6504:Problem E. Split The Tree

题目描述
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 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
输出解释
Print one number denotes the maximal score
输入样例
3
1 1
1 2 2
3
1 1
1 1 1
输出样例
3
2
来自杭电HDUOJ的附加信息
Recommend

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-6504

最后修改于 2020-10-25T23:31:55+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
7000/4000MS(Java/Others) 262144/262144K(Java/Others)