测评会员优惠活动进行中 · 开通 VIP,有效期内测评不限次 VIP 优惠中 · 测评不限次 立即查看

A8406. Matchmaker

编程题 普及/提高-

题目描述

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.
上一题 去做题 下一题