#P4577. [FJOI2018] 领导集团问题

    ID: 3525 远端评测题 1000ms 250MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2018线段树各省省选福建位运算,按位差分

[FJOI2018] 领导集团问题

Description

A company’s leadership structure can be represented by a leadership tree. Each company member corresponds to a node viv_i in the tree, and each member has a corresponding level wiw_i. The higher the leader is in the hierarchy, the smaller their level value wiw_i 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 viv_i and vjv_j, if viv_i is a descendant of vjv_j, then wiwjw_i \ge w_j.

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 nn, denoting the number of nodes in the leadership tree.

The next line contains nn integers. The ii-th number denotes wiw_i.

In the following n1n - 1 lines, the ii-th line contains an integer viv_i, meaning that viv_i is the parent of node i+1i + 1.

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 10%10\% of the testdata, n20n \le 20.

For 40%40\% of the testdata, n2000n \le 2000.

For 100%100\% of the testdata, 1n2×1051 \le n \le 2 \times 10 ^ 5, 0<wi1090 < w_i \le 10 ^ 9.

Translated by ChatGPT 5