#P8258. [CTS2022] 独立集问题
[CTS2022] 独立集问题
Problem Description
Xiao E likes to create Maximum Weight Independent Set problems.
Next, he came up with Maximum Weight Independent Set problems.
But unlike before, this time he wants to merge these problems into a single problem.
Xiao E has AIs, numbered from to .
At the beginning, the -th AI stores one Maximum Weight Independent Set problem prepared in advance by Xiao E, with difficulty .
Some AIs can communicate with each other. For all , the -th AI can communicate directly with the -th AI, where . Therefore, these AIs form a tree. In addition, any other pairs of AIs cannot communicate with each other directly.
Each time, Xiao E can choose an AI that currently stores a Maximum Weight Independent Set problem, and merge it with all problems on AIs that can communicate directly with it, forming a new Maximum Weight Independent Set problem. When merging, there is always a loss of difficulty, so it is impossible to simply add up all difficulties. The difficulty of the new Maximum Weight Independent Set problem equals the sum of the difficulties of the problems on those AIs that can communicate directly with it, minus the difficulty of the problem originally stored on the chosen AI. Then, the difficulties of the problems on those directly communicating AIs become .
Xiao E wants to perform several operations so that the problem difficulties on AIs all become , and then publish the final problem stored in the last remaining AI.
Due to the problem setter's twisted mindset, Xiao E wants the difficulty of the final Maximum Weight Independent Set problem to be as large as possible.
He asks you to help solve this problem, and says that if you succeed, then when publishing that Maximum Weight Independent Set problem, he will help you submit a reference solution code.
Input Format
The first line contains a positive integer .
The second line contains integers, where the -th one denotes .
The third line contains positive integers, where the -th one denotes .
Output Format
Output one integer in a single line, representing the answer.
4
-1 2 3 4
1 1 1
10
Hint
Constraints: .
Constraints: .
Constraints: .
Subtask 1 (13 points): .
Subtask 2 (6 points): .
Subtask 3 (11 points): .
Subtask 4 (13 points): .
Subtask 5 (22 points): .
Subtask 6 (35 points): no special properties.
Translated by ChatGPT 5