#P14023. [ICPC 2024 Nanjing R] 社交媒体
[ICPC 2024 Nanjing R] 社交媒体
Description
On a social media platform, users can leave comments under others' posts to express their thoughts. However, these comments are not visible to everyone. Specifically, for user to see user 's comments under user 's post, he/she has to be friends with both and at the same time. If a user leaves a comment under his/her own post, all his/her friends can see this comment.
As an active user on this platform, you would like to see as many comments as possible. There are users (not counting you) on the platform, numbered from to . There are also comments on the platform, but you might not be able to see them all because you only have friends. As you need to participate in the 2024 ICPC Asia Nanjing Regional Contest, you don't have time to make too many new friends. What's the maximum number of comments you can see if you make at most two new friends on the platform?
Input Format
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 three integers , , and (, ) indicating the number of your friends, the number of comments, and the number of users (not counting you) on the platform.
The second line contains distinct integers () indicating your friends on the platform.
For the following lines, the -th line contains two integers and () indicating a comment written by user under user 's post.
It's guaranteed that neither the sum of nor the sum of of all test cases will exceed .
Output Format
For each test case, output one line containing one integer, indicating the maximum number of comments you can see if you make at most two new friends on the platform.
5
4 12 7
5 7 3 6
3 6
2 2
1 4
2 4
1 3
7 6
4 1
5 4
1 1
1 1
2 1
3 7
2 7 6
2 4
1 2
3 2
2 5
5 4
2 6
4 6
2 6
1 1 2
1
1 2
2 1 2
1 2
1 2
2 1 100
24 11
11 24
9
5
1
1
1
Hint
For the first sample test case, you can make friends with user and .
For the second sample test case, you can make friends with user and .
For the third sample test case, you can make friends with user .
For the fourth and fifth sample test cases, you don't need to make new friends because you can already see all comments.
京公网安备 11011102002149号