题库练习 Matchmaker
← 上一题 下一题 →

A8406 | Matchmaker

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

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
C++ 编辑器
输入
输出