#P7477. 「C.E.L.U-02」划分可重集
「C.E.L.U-02」划分可重集
Description
You are given a sequence of length . Please partition it into two multisets and . You will partition from left to right, and each number must be put into at least one multiset.
A number can be put into if and only if all with have not been put into the current .
A number can be put into if and only if all with have not been put into the current .
At the same time, pairs of relations are given. Each relation means that and cannot be put into the same multiset. Find the minimum that makes a successful partition possible. If no valid partition exists, output -1.
Input Format
The first line contains two integers , as described in the statement.
The next line contains integers, representing .
The following lines each contain two integers, representing one relation.
Output Format
Output one integer, the answer.
6 0
6 2 8 5 7 3
2
10 3
1 3 4 3 8 2 3 4 5 6
2 3
6 7
1 9
5
Hint
Sample Explanation
Sample Explanation 1
The following is one valid partition:
|6|2|8|5|7|3|
|:---:|:---:|:---:|:---:|:---:|:---:|
|a|b|b|a|b|a|
Sample Explanation 2
The following is one valid partition:
|1|3|4|3|8|2|3|4|5|6|
|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|
|b|b|a|b|a|b|a|a|a|b|
Constraints
| Test ID | ||
|---|---|---|
For of the testdata, and . It is guaranteed that , and there are no duplicate pairs .
Translated by ChatGPT 5
京公网安备 11011102002149号