#P9886. [ICPC 2018 Qingdao R] Kawa Exam
[ICPC 2018 Qingdao R] Kawa Exam
题目描述
BaoBao is taking an online exam of the Kawa programming language, which consists of multiple choice questions. The exam is not easy, as for each question, BaoBao needs to select the one and only one correct answer from available choices! But don't worry, as an active committer of the famous \textit{open-kdk}, BaoBao obviously knows all the correct answers.
Although BaoBao is an expert in Kawa, the developers of the exam system are definitely not experts in software engineering. There are bugs in the exam system, and the -th bug can be described as , which means that BaoBao must select the same choice for question and (even if the choice he selects is incorrect!).
Time is limited, and the exam must go on. The developers only have time to fix one bug. Now the developers are wondering, for all , what's the maximum possible number of questions BaoBao can correctly answer if they fix the -th bug. Please write a program to solve this problem so that the developers can select a proper bug to fix.
输入格式
There are multiple test cases. The first line of the input contains an integer , indicating the number of test cases. For each test case:
The first line contains two integers and (, ), indicating the number of questions and the number of bugs.
The second line contains integers (), where indicates the correct answer for question .
For the following lines, the -th line has two integers and (), indicating the -th bug.
It's guaranteed that neither the sum of nor the sum of over all test cases will exceed .
输出格式
For each test case output one line containing integers separated by a space, where indicates the maximum possible number of questions BaoBao can correctly answer if the -th bug is fixed.
Please, DO NOT output extra spaces at the end of each line, or your answer may be considered incorrect!
3
7 5
1 2 1 2 1 2 1
1 2
1 3
2 4
5 6
5 7
3 3
1 2 3
1 2
1 3
2 3
2 3
12345 54321
1 2
1 2
1 1
6 5 5 5 4
1 1 1
1 1 1
提示
The following table explains the first sample test case.
- The
possible choicescolumn indicates a possible set of choices to each question BaoBao can select, leading to a maximum possible number of correctly answered questions; - The
correctcolumn indicates the number of correctly answered questions using the set of choices provided in thepossible choicescolumn.
For the second sample test case, no matter which bug is fixed, BaoBao has to select the same choice for all the three questions. As the correct answer for each question is different, BaoBao can only correctly answer 1 question.
For the third sample test case, note that even if the developers fix the first bug, the second bug is still taking effect and BaoBao still has to select the same choice for the two problems. It's the same if the second bug is fixed.