#P6621. [省选联考 2020 A 卷] 魔法商店
[省选联考 2020 A 卷] 魔法商店
Description
Lili and Lunlun came to a magic shop. There are gifts in the shop, numbered from to . Gift has charm value and price .
They want to buy some gifts, but their requirement is strange. Suppose the set of gifts they buy is . They require that for any non-empty subset of , the XOR sum of the charm values of all gifts in is non-zero, i.e., $c_{t_1} \oplus c_{t_2} \oplus \cdots \oplus c_{t_q} \neq 0$. Here, denotes the XOR operation. On top of this, they also want the number of gifts they buy to be as large as possible.
For example, let . Then does not satisfy the requirement, because . Sets and satisfy the requirement: every non-empty subset has a non-zero XOR sum. Set is not valid because the number of gifts it contains is not maximal.
There may be many gift sets that satisfy their requirement, so the shop owner picked two such sets and for them (obviously they contain the same number of gifts). Lunlun likes set , but Lili prefers set . To make Lili agree to buy set , Lunlun decides to use magic to change gift prices. More specifically, Lunlun can spend magic power to change the price of gift to any integer . Each gift’s price can be changed at most once.
Lunlun wants that after changing prices, is the set with the minimum total price among all gift sets that satisfy the requirement, and is the set with the maximum total price among all such gift sets (the total price of a set is the sum of the prices of all gifts it contains). Please help Lunlun compute the minimum magic power he must spend to achieve his goal.
Input Format
The first line contains two integers , representing the total number of gifts and the number of gifts contained in set , respectively.
The second line contains integers , where the -th integer is the charm value of gift .
The third line contains integers , where the -th integer is the price of gift .
The fourth line contains integers , representing the indices of gifts in set . The data guarantees that all are pairwise distinct.
The fifth line contains integers , representing the indices of gifts in set . The data guarantees that all are pairwise distinct.
The data guarantees , and both sets and satisfy their requirement.
Output Format
Output one integer in a single line, representing the minimum magic power Lunlun needs to spend.
5 3
1 2 5 6 7
4 4 2 1 3
1 2 3
2 4 5
6
Hint
Sample 1 Explanation
The valid gift sets are: $\{1,2,3\},\{1,2,4\},\{1,2,5\},\{1,3,4\},\{1,3,5\},\{2,3,4\},\{2,4,5\},\{3,4,5\}$.
One optimal repricing plan is: , .
Sample 2
See the attached files shop2.in and shop2.ans.
Sample 3
See the attached files shop3.in and shop3.ans.
Constraints
For all testdata: , , , .
The specific limits for each test point are shown in the table below:
| Test Point ID | Special Constraint | ||
|---|---|---|---|
| and are the same | |||
| None |
Translated by ChatGPT 5
京公网安备 11011102002149号