F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Problem E. Split The Tree

Time 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
3 1 1 1 2 2 3 1 1 1 1 1
 

Sample Output
3 2
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 17:18:04, Gzip enabled