CF1475C.Ball in Berland
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
At the school where Vasya is studying, preparations are underway for the graduation ceremony. One of the planned performances is a ball, which will be attended by pairs of boys and girls.
Each class must present two couples to the ball. In Vasya's class, a boys and b girls wish to participate. But not all boys and not all girls are ready to dance in pairs.
Formally, you know k possible one-boy-one-girl pairs. You need to choose two of these pairs so that no person is in more than one pair.
For example, if a=3, b=4, k=4 and the couples (1,2), (1,3), (2,2), (3,4) are ready to dance together (in each pair, the boy's number comes first, then the girl's number), then the following combinations of two pairs are possible (not all possible options are listed below):
- (1,3) and (2,2);
- (3,4) and (1,3);
But the following combinations are not possible:
- (1,3) and (1,2) — the first boy enters two pairs;
- (1,2) and (2,2) — the second girl enters two pairs;
Find the number of ways to select two pairs that match the condition above. Two ways are considered different if they consist of different pairs.
在瓦夏就读的学校,毕业典礼的筹备工作正在紧张进行中。其中一项计划中的节目是一场舞会,将由若干对男女学生共同参加。
每个班级必须派出两对组合参加舞会。在瓦夏所在的班级中,共有 a 名男生和 b 名女生希望参与。但并非所有男生、也并非所有女生都愿意结对共舞。
形式化地说,已知有 k 个可能的“一男一女”配对。你需要从中选出两对,使得任意一个人至多出现在其中一对中(即不能重复出现)。
例如,若 a=3,b=4,k=4,且以下四对组合愿意共舞:(1,2)、(1,3)、(2,2)、(3,4)(每对中第一个数为男生编号,第二个数为女生编号),则以下两对组合的选取是可行的(下方未列出所有可能方案):
- (1,3) 和 (2,2);
- (3,4) 和 (1,3);
但以下组合不可行:
- (1,3) 和 (1,2) —— 第一名男生同时出现在两对中;
- (1,2) 和 (2,2) —— 第二名女生同时出现在两对中;
请计算满足上述条件的、选出两对组合的方案总数。若两个方案所包含的配对不完全相同,则视为不同方案。
输入格式
The first line contains one integer t (1≤t≤104) — the number of test cases. Then t test cases follow.
The first line of each test case contains three integers a, b and k (1≤a,b,k≤2⋅105) — the number of boys and girls in the class and the number of couples ready to dance together.
The second line of each test case contains k integers a1,a2,…ak. (1≤ai≤a), where ai is the number of the boy in the pair with the number i.
The third line of each test case contains k integers b1,b2,…bk. (1≤bi≤b), where bi is the number of the girl in the pair with the number i.
It is guaranteed that the sums of a, b, and k over all test cases do not exceed 2⋅105.
It is guaranteed that each pair is specified at most once in one test case.
第一行包含一个整数 t(1≤t≤104)—— 测试用例的数量。随后是 t 个测试用例。
每个测试用例的第一行包含三个整数 a、b 和 k(1≤a,b,k≤2⋅105)—— 分别表示班级中男生人数、女生人数以及愿意一起跳舞的舞伴对数。
每个测试用例的第二行包含 k 个整数 a1,a2,…,ak(1≤ai≤a),其中 ai 表示第 i 对舞伴中的男生编号。
每个测试用例的第三行包含 k 个整数 b1,b2,…,bk(1≤bi≤b),其中 bi 表示第 i 对舞伴中的女生编号。
保证所有测试用例中 a、b 和 k 的总和均不超过 2⋅105。
保证在每个测试用例中,每对舞伴至多被指定一次。
输出格式
For each test case, on a separate line print one integer — the number of ways to choose two pairs that match the condition above.
对于每个测试用例,在单独一行中输出一个整数——即满足上述条件的选出两个数对的方法数。
输入输出样例
输入#1
3 3 4 4 1 1 2 3 2 3 2 4 1 1 1 1 1 2 2 4 1 1 2 2 1 2 1 2
输出#1
4 0 2
说明/提示
In the first test case, the following combinations of pairs fit:
- (1,2) and (3,4);
- (1,3) and (2,2);
- (1,3) and (3,4);
- (2,2) and (3,4).
There is only one pair in the second test case.
In the third test case, the following combinations of pairs fit:
- (1,1) and (2,2);
- (1,2) and (2,1).
在第一个测试用例中,以下数对组合满足条件:
- (1,2) 和 (3,4);
- (1,3) 和 (2,2);
- (1,3) 和 (3,4);
- (2,2) 和 (3,4)。
第二个测试用例中仅存在一个数对。
在第三个测试用例中,以下数对组合满足条件:
- (1,1) 和 (2,2);
- (1,2) 和 (2,1)。
输入解题思路,AI测评打分。不知道怎么写?