#P7211. [JOISC 2020] カメレオンの恋
[JOISC 2020] カメレオンの恋
Description
In the JOI Zoo, there are chameleons. of them have gender , and the other have gender .
Each chameleon has its original color, with the following constraints:
- The colors of the -gender chameleons are pairwise distinct.
- For each -gender chameleon, there exists a -gender chameleon with the same color.
Now each chameleon loves exactly one other chameleon, under the following rules:
- Each chameleon only loves a chameleon of the opposite gender.
- Each chameleon and the chameleon it loves have different original colors.
- There is no chameleon that is loved by two different chameleons.
Now you may organize meetings of some chameleons. For each chameleon in the meeting, let be the chameleon that loves.
- If attends the meeting, then the skin color of becomes the original color of .
- Otherwise, the skin color of remains the original color of .
For each meeting you organize, you can count the number of distinct skin colors.
By holding at most meetings, you must determine every pair of chameleons that share the same original color.
Interaction Details
You need to declare two functions before your program:
int Query(const std::vector<int> &p).void Answer(int a, int b).
You need to implement one function: void Solve(int N).
- It is called exactly once for each test case.
- The meaning of is as described in the statement.
Your program may call the following functions:
-
int Query(const std::vector<int> &p)- You may call this function to organize a chameleon meeting.
- is the list of chameleons attending the meeting.
- It returns the number of distinct colors among the attending chameleons.
- All numbers in must be between and , otherwise it will return
Wrong Answer [1]. - All numbers in must be pairwise distinct, otherwise it will return
Wrong Answer [2]. - You may call this function at most times; if you exceed this limit, it will return
Wrong Answer [3].
- You may call this function to organize a chameleon meeting.
-
void Answer(int a, int b)- Call this function to submit a pair of chameleons with the same original color.
- Parameters and indicate that chameleon and chameleon have the same original color.
- You must ensure , otherwise it will return
Wrong Answer [4]. - You must ensure that every chameleon you submit is different from all previously submitted chameleons, otherwise it will return
Wrong Answer [5]. - If the original colors of and are different, it will return
Wrong Answer [6]. - You must call this function exactly times, otherwise it will return
Wrong Answer [7].
- Call this function to submit a pair of chameleons with the same original color.
If you never violate any of the restrictions during the interaction, then you will be accepted.
Input Format
The input format of the interactive library is as follows:
The first line contains an integer .
The second line contains integers , indicating the gender of each chameleon. If , the gender is ; if , the gender is .
The third line contains integers , where is the color of chameleon .
The fourth line contains integers , where indicates that chameleon likes (loves) chameleon . ("稀饭" is a colloquial form of "喜欢", meaning "like".)
Output Format
The output format of the interactive library is as follows:
If you get AC, it outputs one line Accepted: x, where is the number of times you called int Query(const std::vector<int> &p).
If you get WA, it outputs one line Wrong Answer [type], where is the reason for WA. See the interaction details.
4
1 0 1 0 0 1 1 0
4 4 1 2 1 2 3 3
4 3 8 7 6 5 2 1
Hint
Sample Explanation
The sample calls are as follows:
| Library Call | Your Call | Return Value |
| :-: | :-: | :-: |
| Solve(4) | | |
| | Query([]) | |
| | Query([6, 2]) | |
| | Query([8, 1, 6]) | |
| | Query([7, 1, 3, 5, 6, 8]) | |
| | Query([8, 6, 4, 1, 5]) | |
| | Answer(6, 4) | |
| | Answer(7, 8) | |
| | Answer(2, 1) | |
| | Answer(3, 5) | |
sample-02.txt satisfies the constraints of Subtask 1, and sample-03.txt satisfies the constraints of Subtask 4.
Subtasks and Constraints
For of the data, it is guaranteed that , , , , , , and all are pairwise distinct.
| Subtask | Special Property | Score |
|---|---|---|
| None |
Notes
This problem is translated from The 19th Japanese Olympiad in Informatics Spring Training Camp Day 2 T1 カメレオンの恋.
Translated by ChatGPT 5
京公网安备 11011102002149号