CF159B.Matchmaker
普及-
通过率:0%
时间限制:3.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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.
波利卡普斯有 n 支记号笔和 m 个笔帽。每支记号笔由两个数描述:xi 表示颜色,yi 表示直径;相应地,每个笔帽也由两个数描述:aj 表示颜色,bj 表示直径。笔帽 (aj,bj) 能够盖住记号笔 (xi,yi) 当且仅当它们的直径相等,即 bj=yi。此外,若笔帽的颜色与记号笔的颜色也相同(即 aj=xi),则称该记号笔被“美观地”盖住。
请找出一种盖住最多数量记号笔的方式。若存在多种方式能盖住同样多的记号笔,则从中选择“美观地”盖住的记号笔数量最多的方案。
输入格式
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 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.
第一行输入包含两个以空格分隔的整数 n 和 m(1 ≤ n, m ≤ 105),分别表示记号笔的数量和笔帽的数量。
接下来的 n 行描述记号笔。第 i 行包含两个以空格分隔的整数 xi、yi(1 ≤ xi, yi ≤ 1000),分别表示第 i 支记号笔的颜色和直径。
接下来的 m 行描述笔帽。第 j 行包含两个以空格分隔的整数 aj、bj(1 ≤ aj, bj ≤ 1000),分别表示第 j 个笔帽的颜色和直径。
输出格式
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.
输出两个用空格分隔的整数 u 和 v,其中 u 表示在所求最优方案中被闭合的标记数量,v 表示在该方案中被“优美地”闭合的标记数量。注意:你需要找到一种闭合标记数量最多的方案;若存在多种闭合数量相同的方案,则应从中选择“优美地”闭合标记数量最多的方案。
输入输出样例
输入#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.
在第一个测试样例中,第一个标记应由第四个瓶盖关闭,第二个标记应由第一个瓶盖关闭,第三个标记应由第二个瓶盖关闭。因此,将有三个标记被关闭,其中两个标记将被“优美地”关闭——即第一个和第三个标记。
输入解题思路,AI测评打分。不知道怎么写?