300831: CF159B. Matchmaker

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

Description

Matchmaker

题意翻译

### 题目描述 ygg 有 $n$ 只马克笔和 $m$ 个笔盖。我们可以使用二元组 $(a, b)$ 来描述一只笔或一个笔盖,其中 $a$ 表示颜色,$b$ 表示大小。任意一对笔和笔盖只有在**大小相同**的时候才可以配对,如果这一对笔和笔盖**大小相同且颜色相同**,我们就称这一对笔和笔盖为**优秀的配对**。 现在 ygg 希望知道他最多可以构成多少**优秀的配对**,以及最多共有多少对配对。 ### 输入格式 第一行两个整数 $n$ 和 $m$ ,表示笔的数量和笔盖的数量 接下来的 $n$ 行,每行两个整数 $a_i, b_i$ ,表示第 $i$ 只笔的颜色和大小。 接下来的 $m$ 行,每行两个整数 $a_i, b_i$ ,表示第 $i$ 个笔盖的颜色和大小。 ### 输出格式 输出一行,两个整数,表示**优秀**的配对数和**普通**配对数

题目描述

Polycarpus has $ n $ markers and $ m $ marker caps. Each marker is described by two numbers: $ x_{i} $ is the color and $ y_{i} $ is the diameter. Correspondingly, each cap is described by two numbers: $ a_{j} $ is the color and $ b_{j} $ is the diameter. Cap $ (a_{j},b_{j}) $ can close marker $ (x_{i},y_{i}) $ only if their diameters match, that is, $ b_{j}=y_{i} $ . Besides, a marker is considered to be beautifully closed, if the cap color and the marker color match, that is, $ a_{j}=x_{i} $ . Find the way to close the maximum number of markers. If there are several such ways, then choose the one that has the maximum number of beautifully closed markers.

输入输出格式

输入格式


The first input line contains two space-separated integers $ n $ and $ m $ ( $ 1<=n,m<=10^{5} $ ) — the number of markers and the number of caps, correspondingly. Next $ n $ lines describe the markers. The $ i $ -th line contains two space-separated integers $ x_{i} $ , $ y_{i} $ ( $ 1<=x_{i},y_{i}<=1000 $ ) — the $ i $ -th marker's color and diameter, correspondingly. Next $ m $ lines describe the caps. The $ j $ -th line contains two space-separated integers $ a_{j} $ , $ b_{j} $ ( $ 1<=a_{j},b_{j}<=1000 $ ) — the color and diameter of the $ j $ -th cap, correspondingly.

输出格式


Print two space-separated integers $ u,v $ , where $ u $ is the number of closed markers and $ v $ is the number of beautifully closed markers in the sought optimal way. Remember that you have to find the way to close the maximum number of markers, and if there are several such ways, you should choose the one where the number of beautifully closed markers is maximum.

输入输出样例

输入样例 #1

3 4
1 2
3 4
2 4
5 4
2 4
1 1
1 2

输出样例 #1

3 2

输入样例 #2

2 2
1 2
2 1
3 4
5 1

输出样例 #2

1 0

说明

In the first test sample the first marker should be closed by the fourth cap, the second marker should be closed by the first cap and the third marker should be closed by the second cap. Thus, three markers will be closed, and two of them will be beautifully closed — the first and the third markers.

Input

题意翻译

### 题目描述 ygg 有 $n$ 只马克笔和 $m$ 个笔盖。我们可以使用二元组 $(a, b)$ 来描述一只笔或一个笔盖,其中 $a$ 表示颜色,$b$ 表示大小。任意一对笔和笔盖只有在**大小相同**的时候才可以配对,如果这一对笔和笔盖**大小相同且颜色相同**,我们就称这一对笔和笔盖为**优秀的配对**。 现在 ygg 希望知道他最多可以构成多少**优秀的配对**,以及最多共有多少对配对。 ### 输入格式 第一行两个整数 $n$ 和 $m$ ,表示笔的数量和笔盖的数量 接下来的 $n$ 行,每行两个整数 $a_i, b_i$ ,表示第 $i$ 只笔的颜色和大小。 接下来的 $m$ 行,每行两个整数 $a_i, b_i$ ,表示第 $i$ 个笔盖的颜色和大小。 ### 输出格式 输出一行,两个整数,表示**优秀**的配对数和**普通**配对数

加入题单

算法标签: