CF159B.Matchmaker
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Polycarpus has n markers and m marker caps. Each marker is described by two numbers: xi is the color and yi is the diameter. Correspondingly, each cap is described by two numbers: aj is the color and bj is the diameter. Cap (aj,bj) can close marker (xi,yi) only if their diameters match, that is, bj=yi . Besides, a marker is considered to be beautifully closed, if the cap color and the marker color match, that is, aj=xi .
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<=105 ) — 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 xi , yi ( 1<=xi,yi<=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 aj , bj ( 1<=aj,bj<=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.