P8258 [CTS2022] Maximum Weight Independent Set Problem

Description

Xiao E likes to create Maximum Weight Independent Set problems. Next, he came up with $n$ Maximum Weight Independent Set problems. But unlike before, this time he wants to merge these $n$ problems into a single problem. Xiao E has $n$ AIs, numbered from $1$ to $n$. At the beginning, the $i$-th AI stores one Maximum Weight Independent Set problem prepared in advance by Xiao E, with difficulty $d_i$. Some AIs can communicate with each other. For all $2 \le i \le n$, the $i$-th AI can communicate directly with the $c_i$-th AI, where $c_i

Input Format

The first line contains a positive integer $n$. The second line contains $n$ integers, where the $i$-th one denotes $d_i$. The third line contains $n-1$ positive integers, where the $i$-th one denotes $c_{i+1}$.

Output Format

Output one integer in a single line, representing the answer.

Explanation/Hint

Constraints: $1\le n\le 351493$. Constraints: $1\le c_i 0$. Subtask 3 (11 points): $n\le 7$. Subtask 4 (13 points): $n\le 16$. Subtask 5 (22 points): $n\le 100$. Subtask 6 (35 points): no special properties. Translated by ChatGPT 5