#P4577. [FJOI2018] 领导集团问题
[FJOI2018] 领导集团问题
Description
A company’s leadership structure can be represented by a leadership tree. Each company member corresponds to a node in the tree, and each member has a corresponding level . The higher the leader is in the hierarchy, the smaller their level value is. If there is an edge between any two nodes in the tree, it means the two corresponding members belong to the same department.
The leadership group problem is to determine the company’s largest department based on the leadership tree. In other words, we need to find the largest subset of nodes in the leadership tree such that for any nodes and , if is a descendant of , then .
Programming task: For any given leadership tree, compute the size of the largest valid department node subset in the leadership tree.
Input Format
The first line contains a positive integer , denoting the number of nodes in the leadership tree.
The next line contains integers. The -th number denotes .
In the following lines, the -th line contains an integer , meaning that is the parent of node .
Output Format
Output the number of members in the largest department found.
6
2 5 1 3 5 4
1
1
2
2
4
4
Hint
For of the testdata, .
For of the testdata, .
For of the testdata, , .
Translated by ChatGPT 5
京公网安备 11011102002149号