QOJ.ac

QOJ

时间限制: 4 s 内存限制: 1024 MB 总分: 100

#3802. “偶”除法

统计

如果谈论通常意义上的“偶数划分”,它意味着将事物平均分配。今天,你需要思考一些不同的东西。一个图需要被划分为若干个子图,使得每个子图的节点数均为偶数,即二的倍数。

你被给定一个节点数为偶数的无向连通图。该图需要被划分为若干个子图,使得所有子图都是连通的且节点数为偶数,直到无法再进行这样的划分为止。图 I.1 展示了一个例子。原图有 8 个节点,被划分为节点数分别为 4、2 和 2 的子图。它们的所有节点数均为偶数。

图 I.1. 划分示例(样例输入/输出 1)

用数学语言来说,图的“偶数划分”是指满足以下条件的图节点子集集合 $V_1, \dots, V_k$:

  1. $V_1 \cup \dots \cup V_k$ 是输入图中所有节点的集合,且当 $i \neq j$ 时,$V_i \cap V_j = \emptyset$。
  2. 每个 $V_i$ 均非空,且包含偶数个元素。
  3. 每个 $V_i$ 导出一个连通子图。换句话说,$V_i$ 中的任意节点都可以仅通过输入图中连接 $V_i$ 内两个节点的边相互到达。
  4. 不存在进一步的划分。对于任何 $U_1 \cup U_2 = V_i$,通过将 $V_i$ 替换为两个集合 $U_1$ 和 $U_2$ 所得到的划分不满足条件 1、2 或 3 中的任意一条。

你的任务是找到给定图的一个偶数划分。

输入格式

输入包含单个测试用例,格式如下:

$n \ m$ $x_1 \ y_1$ $\vdots$ $x_m \ y_m$

第一行包含两个整数 $n$ 和 $m$。第一个整数 $n$ ($2 \le n \le 10^5$) 是一个偶数,表示要划分的图的节点数。第二个整数 $m$ ($n - 1 \le m \le 10^5$) 是图的边数。

图的节点编号从 $0$ 到 $n - 1$。

随后的 $m$ 行表示图的边。一行 $x_i \ y_i$ ($0 \le x_i < y_i < n$) 表示存在一条连接节点 $x_i$ 和 $y_i$ 的边。图中没有重复的边。保证输入图是连通的。

输出格式

如果存在将给定图的节点集划分为子集 $V_1, \dots, V_k$ 的偶数划分,请在输出的第一行打印 $k$。接下来的 $k$ 行应描述子集 $V_1, \dots, V_k$。子集的顺序无关紧要。第 $i$ 行应以 $V_i$ 的大小开头,后跟 $V_i$ 中元素的节点编号,并用空格分隔。节点编号的顺序也无关紧要。

如果存在多个偶数划分,输出其中任意一个即可。

样例

样例输入 1

8 9
0 1
1 2
2 3
0 4
1 6
3 7
4 5
5 6
6 7

样例输出 1

3
2 3 7
2 4 5
4 0 1 2 6

样例输入 2

2 1
0 1

样例输出 2

1
2 0 1

说明

在样例 2 中,原图节点集的单元素集合本身就是一个偶数划分。

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.