QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 256 MB Total points: 100

#14962. 新型城市化

统计

Anihc 国有 $n$ 座城市,城市之间存在着一些贸易合作关系,如果城市 $x$ 和城市 $y$ 之间存在贸易协定,那么城市 $x$ 和城市 $y$ 则是一对贸易伙伴(注意:$(x, y)$ 和 $(y, x)$ 是同一对城市)。

为了实现新型城市化,实现统筹城乡一体化以及发挥城市群辐射与带动作用,Anihc 国决定规划新型城市关系。一些城市能够被称为城市群的条件是:这些城市两两都是贸易伙伴。由于 Anihc 国之前也一直很重视城市关系建设,所以可以保证在目前已存在的贸易合作关系的情况下,Anihc 的 $n$ 座城市可以恰好划分为不超过两个城市群。

为了建设新型城市关系,Anihc 国想要选出两个之前并不是贸易伙伴的城市,使这两个城市称为贸易伙伴,并且要求在这两个城市称为贸易伙伴之后,最大城市群的大小至少比他们称为贸易伙伴之前的最大城市群的大小增加 $1$。

Anihc 国需要在下一次会议上讨论扩大建设新型城市关系的问题,所以需要请你求出在哪些城市之间建立贸易伙伴关系可以使得这个条件成立,即建立此关系前后的最大城市群的大小至少相差 $1$。

输入格式

第一行两个整数 $n, m$,表示城市的个数,目前还没有建立贸易伙伴关系的城市的对数。接下来 $m$ 行,每行两个整数 $x, y$,表示城市 $x, y$ 之间目前还没有建立贸易伙伴关系。

输出格式

第一行一个整数 $\text{Ans}$,表示符合条件的城市的对数,注意 $(x, y)$ 与 $(y, x)$ 算同一对城市。

接下来 $\text{Ans}$ 行,每行两个整数,表示一对可以选择来建立贸易伙伴关系的城市。对于一对城市 $x, y$ 请先输出编号更小的哪一个。最后城市对与城市对之间的顺序请按照字典序从小到大输出。

样例数据

样例 1 输入

5 3
1 5
2 4
2 5

样例 1 输出

2
1 5
2 4

子任务

数据点 $1$:$n \le 16$;

数据点 $2$:$n \le 16$;

数据点 $3 \sim 5$:$n \le 100$;

数据点 $6$:$n \le 500$;

数据点 $7 \sim 10$:$n \le 10\,000$;

对于所有的数据保证:$n \le 10\,000$,$0 \le m \le \min\left(150\,000, \frac{ n(n-1) }{2}\right)$,$1 \le x, y \le n$,保证输入的城市关系中不会出现 $(x, x)$ 这样的关系,同一对城市也不会出现两次(无重边,无自环)。

Discussions

About Discussions

The discussion section is only for posting: Editorials, 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. Submitting multiple issues may cause your account to be banned.
  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.