CF330B.Road Construction

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

A country has nn cities. Initially, there is no road in the country. One day, the king decides to construct some roads connecting pairs of cities. Roads can be traversed either way. He wants those roads to be constructed in such a way that it is possible to go from each city to any other city by traversing at most two roads. You are also given mm pairs of cities — roads cannot be constructed between these pairs of cities.

Your task is to construct the minimum number of roads that still satisfy the above conditions. The constraints will guarantee that this is always possible.

输入格式

The first line consists of two integers nn and mm .

Then mm lines follow, each consisting of two integers aia_{i} and bib_{i} ( 1<=ai,bi<=n1<=a_{i},b_{i}<=n , aibia_{i}≠b_{i} ), which means that it is not possible to construct a road connecting cities aia_{i} and bib_{i} . Consider the cities are numbered from 1 to nn .

It is guaranteed that every pair of cities will appear at most once in the input.

输出格式

You should print an integer ss : the minimum number of roads that should be constructed, in the first line. Then ss lines should follow, each consisting of two integers aia_{i} and bib_{i} ( 1<=ai,bi<=n,aibi1<=a_{i},b_{i}<=n,a_{i}≠b_{i} ), which means that a road should be constructed between cities aia_{i} and bib_{i} .

If there are several solutions, you may print any of them.

输入输出样例

  • 输入#1

    4 1
    1 3
    

    输出#1

    3
    1 2
    4 2
    2 3
    

说明/提示

This is one possible solution of the example:

These are examples of wrong solutions:

The above solution is wrong because it doesn't use the minimum number of edges ( 44 vs 33 ). In addition, it also tries to construct a road between cities 11 and 33 , while the input specifies that it is not allowed to construct a road between the pair. The above solution is wrong because you need to traverse at least 33 roads to go from city 11 to city 33 , whereas in your country it must be possible to go from any city to another by traversing at most 22 roads. Finally, the above solution is wrong because it must be possible to go from any city to another, whereas it is not possible in this country to go from city 11 to 33 , 22 to 33 , and 44 to 33 .

首页