CF159B.Matchmaker

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Polycarpus has nn markers and mm marker caps. Each marker is described by two numbers: xix_{i} is the color and yiy_{i} is the diameter. Correspondingly, each cap is described by two numbers: aja_{j} is the color and bjb_{j} is the diameter. Cap (aj,bj)(a_{j},b_{j}) can close marker (xi,yi)(x_{i},y_{i}) only if their diameters match, that is, bj=yib_{j}=y_{i} . Besides, a marker is considered to be beautifully closed, if the cap color and the marker color match, that is, aj=xia_{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 nn and mm ( 1<=n,m<=1051<=n,m<=10^{5} ) — the number of markers and the number of caps, correspondingly.

Next nn lines describe the markers. The ii -th line contains two space-separated integers xix_{i} , yiy_{i} ( 1<=xi,yi<=10001<=x_{i},y_{i}<=1000 ) — the ii -th marker's color and diameter, correspondingly.

Next mm lines describe the caps. The jj -th line contains two space-separated integers aja_{j} , bjb_{j} ( 1<=aj,bj<=10001<=a_{j},b_{j}<=1000 ) — the color and diameter of the jj -th cap, correspondingly.

输出格式

Print two space-separated integers u,vu,v , where uu is the number of closed markers and vv 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.

首页