#P3731. [HAOI2017] 新型城市化

    ID: 1275 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2017河南各省省选强连通分量,缩点二分图

[HAOI2017] 新型城市化

Description

There are nn cities in Anihc. Some cities have trade cooperation relations: if there is a trade agreement between city xx and city yy, then city xx and city yy are a pair of trade partners (note: (x,y)(x,y) and (y,x)(y,x) denote the same pair of cities).

To implement new-type urbanization, integrate urban and rural development, and leverage the radiation and driving role of city clusters, the country decides to plan new city relations. A set of cities can be called a city cluster if every pair among them are trade partners. Since Anihc has long attached importance to building city relations, it is guaranteed that, under the currently existing trade cooperation relations, the nn cities can be partitioned into at most two city clusters.

To build new city relations, Anihc wants to select two cities that are not yet trade partners, make them trade partners, and requires that after these two cities become trade partners, the size of the largest city cluster is at least 11 larger than the size of the largest city cluster before they became partners.

Anihc needs to discuss expanding the construction of new city relations at the next meeting, so you are asked to find all pairs of cities between which establishing a trade partnership would satisfy this condition, i.e., the size of the largest city cluster after establishing the partnership is at least 11 greater than before.

Input Format

The first line contains 22 integers n,mn, m, the number of cities and the number of unordered city pairs that have not yet established a trade partnership.

The next mm lines each contain 22 integers x,yx, y, indicating that cities xx and yy have not yet established a trade partnership.

Output Format

Output one integer ans\text{ans} on the first line, the number of qualifying city pairs.

Then output ans\text{ans} lines, each containing two integers, representing a pair of cities that can be chosen to establish a trade partnership. For a pair of cities x,yx, y, output the smaller index first. Finally, sort the pairs in ascending lexicographic order.

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

Hint

Test point 11: n16n \le 16.

Test point 22: n16n \le 16.

Test points 353 \sim 5: n100n \le 100.

Test point 66: n500n \le 500.

Test points 7107 \sim 10: n104n \le 10^4.

For all testdata, it is guaranteed that $n \le 10^4, 0 \le m \le \min(1.5 \times 10^5, \dfrac{n(n-1)}{2})$. It is guaranteed that there is no relation of the form (x,x)(x, x) in the input, and no pair of cities appears twice (no multiple edges, no self-loops).

Translated by ChatGPT 5