QOJ.ac

QOJ

시간 제한: 3.0 s 메모리 제한: 512 MB 총점: 100 해킹 가능 ✓

#16712. 帝国历史

통계

很久以前,有两个伟大的王国 Someland 和 Otherland。每个王国都由至少两个城市以及连接它们的一些道路组成。仅通过这些道路,就可以从任意一个王国的任意城市到达该王国的任意其他城市。然而,属于不同王国的任意两个城市之间最初没有道路相连。

正如一个古老的传说所说,当这两个王国被“新路皇帝”(Emperor of New Roads)征服时,他决定通过做他最擅长的事——修建新道路——来将它们联合起来。他从 Someland 中挑选了一个非空城市子集 $u_1, u_2, \dots, u_k$,并从 Otherland 中挑选了一个非空城市子集 $v_1, v_2, \dots, v_l$。

然后,他下令在每对城市 $u_x$ 和 $v_y$($1 \le x \le k, 1 \le y \le l$)之间修建一条新道路,从而增加了 $k \cdot l$ 条新道路。

几百年过去了。从那时起,没有新建任何城市或道路,也没有任何城市或道路被摧毁。然而,现在没有人确切记得哪些城市曾是 Someland 的一部分,哪些城市曾是 Otherland 的一部分。今年,帝国计划庆祝千禧年,你被雇用来恢复历史真相,并确定 Someland 和 Otherland 之间可能的一种城市划分方案。

输入格式

第一行包含两个整数 $n$ 和 $m$($4 \le n \le 200\,000$,$n - 1 \le m \le 200\,000$),分别表示当前帝国地图上的城市数量和道路数量。

接下来的 $m$ 行,每行包含两个整数 $u_i$ 和 $v_i$($1 \le u_i, v_i \le n$,$u_i \neq v_i$),表示第 $i$ 条道路连接的两个城市的编号。没有道路会连接城市自身,且任意两个城市之间最多只有一条道路。

输出格式

第一行应包含两个整数 $n_1$ 和 $k$($2 \le n_1 \le n - 2$,$1 \le k \le n_1$),分别表示 Someland 的城市数量以及新路皇帝从 Someland 中选出的城市数量。

第二行应包含 $n_1$ 个互不相同的整数,表示曾经属于 Someland 的帝国城市编号。其中前 $k$ 个整数应表示被选出用于修建新道路的城市子集。

第三行应包含两个整数 $n_2$ 和 $l$($n_2 = n - n_1$,$1 \le l \le n_2$),分别表示 Otherland 的城市数量以及被选出用于修建新道路的 Otherland 城市数量。

第四行应以与 Someland 相同的格式列出 Otherland 的城市。

在你的方案中,Someland 和 Otherland 内部(仅通过各自原有的道路)都必须是连通的。由于没有人真正关心这两个王国最初的具体样貌,如果存在多种可能的解,输出其中任意一种即可。数据保证至少存在一种可能的解。

样例

输入样例 1

6 12
1 2
1 3
2 3
1 4
1 5
1 6
2 4
2 5
2 6
3 4
3 5
3 6

输出样例 1

4 4
3 4 5 6
2 2
1 2

输入样例 2

6 10
1 2
1 3
1 4
1 5
6 2
6 3
6 4
6 5
2 3
4 5

输出样例 2

2 2
4 5
4 2
1 6 2 3

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.