#P10332. [UESTCPC 2024] 一站到底

[UESTCPC 2024] 一站到底

Problem Description

Suppose you are Li Hua, a student at University of Electronic Science and Technology of China. In an episode of “One Stand to the End” in the year 4202, you participate as a contestant in the recording of the show. Unlike the rules from more than 2000 years ago, the show will not have stages where contestants duel in pairs and compete to buzz in or take turns answering. Instead, each contestant answers questions in a solo format. The specific rules are as follows.

Before your answering stage begins, the system will draw nn questions from the question bank. Each question has a score aia_i based on its difficulty. The host will announce all question statements and their scores at the beginning, and then your answering stage starts.

To make the show more interesting, during the answering stage, you cannot choose the order of questions freely. Specifically, except for Question 11, every other question has exactly one prerequisite question. You can answer a question only after you have correctly answered its prerequisite. The production team guarantees that the prerequisite question index of Question ii is always less than ii.

In addition, if you submit a wrong answer when answering a question, the floor beneath you will open immediately, you will fall, and your answering stage ends. The sum of the scores of all previously answered correctly questions is your final score. If you answer all questions correctly, then the sum of the scores of all questions is your final score.

Now you have read all the questions. Based on your knowledge, you estimate the probability pip_i that you will answer each question correctly. You need to design the best problem-solving strategy in the shortest time to maximize your expected score. Please output this score, and write an English essay of at least 120 words about the experience of participating in this show.

Input Format

The first line contains a positive integer nn (2n105)(2\le n\le 10^5), representing the number of questions.

The next line contains nn positive integers a1,a2,,ana_1,a_2,\ldots,a_n (1ai106)(1\leq a_i\leq 10^6), where aia_i is the score of Question ii.

The next line contains nn real numbers p1,p2,,pnp_1,p_2,\ldots,p_n (0<pi<1)(0<p_i<1), where pip_i is the probability that you answer Question ii correctly.

The next line contains n1n-1 positive integers t1,t2,,tn1t_1,t_2,\ldots,t_{n-1} (1tii)(1\leq t_i\leq i), where tit_i is the index of the prerequisite question for Question i+1i+1.

Output Format

Output one real number, representing the expected score under the optimal strategy.

Suppose your output is aa and the correct answer is bb. Your answer will be considered correct if and only if abmax(1,b)109\frac{|a-b|}{\max(1,b)}\le 10^{-9}.

5
5 4 3 2 1
0.9 0.89 0.88 0.87 0.86
1 1 2 2
11.572522416

Hint

In the sample, the questions with higher scores also have higher probabilities of being answered correctly, so it is clearly optimal to answer in the order 1,2,3,4,51,2,3,4,5.

Translated by ChatGPT 5