QOJ.ac

QOJ

実行時間制限: 4 s メモリ制限: 1024 MB 満点: 100

#5670. 分组客人

統計

聚会上共有 $n$ 位客人。每位客人都有 2 种不同的爱好。没有两位客人拥有完全相同的爱好集合。聚会主办方希望将客人分成大小为 2 或 3 的小组,使得组内每两位客人都有一个共同的爱好。也就是说,每个小组属于以下情况之一:

  • 类型 A:由两位拥有一个共同爱好的客人组成的小组;
  • 类型 B:由三位客人组成的小组,他们三人都有一个共同的爱好;
  • 类型 C:由三位客人组成的小组,其中每两位客人都有一个共同的爱好,且不属于类型 B 的情况。

主办方希望将未分配到任何小组的客人数量 $\alpha$ 降至最低。如果存在多个方案都能达到最小的 $\alpha$,我们需要找到一个方案,在保持 $\alpha$ 最小的前提下,使所使用的类型 B 小组数量 $\beta$ 最小。请编写程序确定这两个数字。

图 15:上图给出了第三个测试用例的两种不同解决方案。右侧的解决方案没有使用任何类型 B 小组,因此它比左侧的方案更好。

输入格式

每个测试用例包含 $n+1$ 行。第一行给出两个整数 $n$ 和 $h$。接下来的 $n$ 行中,第 $(i+1)$ 行包含两个整数 $x$ 和 $y$,其中 $1 \le x, y \le h$,表示第 $i$ 位客人拥有爱好 $x$ 和 $y$。

数据范围

  • $2 \le n \le 10^6$
  • $3 \le h \le 2n$

输出格式

找到一个最优解,并输出未分配客人的数量 $\alpha$ 以及方案中使用的类型 B 小组的数量 $\beta$。注意,我们的目标是先最小化 $\alpha$,然后在保持 $\alpha$ 最小的前提下最小化 $\beta$。

样例

输入格式 1

2 4
1 2
3 4

输出格式 1

2 0

输入格式 2

2 3
1 2
3 1

输出格式 2

0 0

输入格式 3

5 5
1 2
2 3
2 4
5 2
5 4

输出格式 3

0 0

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.