308160: CF1475C. Ball in Berland

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Ball in Berland

题意翻译

### 题意 在毕业典礼上,有 $a$ 个男孩和 $b$ 个女孩准备跳舞,不是所有的男孩和女孩都准备结伴跳舞。 现在你知道 $k$ 个可能的舞伴,你需要选择其中的两对,以便使没有人重复地出现在舞伴里,求可能的数量。 ### 输入格式 第一行一个整数 $t$ 表示数据组数 每个数据的第一行三个整数 $a,b,k$ ,分别表示男孩数,女孩数和舞伴数。 每个数据的第二行 $a_1,a_2,...,a_k$ 表示男孩 $a_i$ 在第 $i$ 对舞伴里 每个数据的第三行 $b_1,b_2,...,b_k$ 表示女孩 $b_i$ 在第 $i$ 对舞伴里 ### 输出格式 一行一个整数表示每个数据的方案数 ### 说明/提示 $1 \leq t \leq 10^4$ $1\leq a,b,k \leq 2\cdot 10^5$

题目描述

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.

输入输出格式

输入格式


The first line contains one integer $ t $ ( $ 1 \le t \le 10^4 $ ) — 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 \le a, b, k \le 2 \cdot 10^5 $ ) — 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 $ a_1, a_2, \ldots a_k $ . ( $ 1 \le a_i \le a $ ), where $ a_i $ is the number of the boy in the pair with the number $ i $ . The third line of each test case contains $ k $ integers $ b_1, b_2, \ldots b_k $ . ( $ 1 \le b_i \le b $ ), where $ b_i $ 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 \cdot 10^5 $ . It is guaranteed that each pair is specified at most once in one test case.

输出格式


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) $ .

Input

题意翻译

### 题意 在毕业典礼上,有 $a$ 个男孩和 $b$ 个女孩准备跳舞,不是所有的男孩和女孩都准备结伴跳舞。 现在你知道 $k$ 个可能的舞伴,你需要选择其中的两对,以便使没有人重复地出现在舞伴里,求可能的数量。 ### 输入格式 第一行一个整数 $t$ 表示数据组数 每个数据的第一行三个整数 $a,b,k$ ,分别表示男孩数,女孩数和舞伴数。 每个数据的第二行 $a_1,a_2,...,a_k$ 表示男孩 $a_i$ 在第 $i$ 对舞伴里 每个数据的第三行 $b_1,b_2,...,b_k$ 表示女孩 $b_i$ 在第 $i$ 对舞伴里 ### 输出格式 一行一个整数表示每个数据的方案数 ### 说明/提示 $1 \leq t \leq 10^4$ $1\leq a,b,k \leq 2\cdot 10^5$

加入题单

算法标签: