Codeforces Round 192 (Div. 2)
B
Road Construction
Codeforces
1300
原题
← AC →
翻译中…

A country has $*n*$ 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 $*m*$ 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.

翻译中…

Input

翻译中…

The first line consists of two integers $*n*$ and $*m*$ image.

翻译中…

Then $*m*$ lines follow, each consisting of two integers $*a*_{*i*}$ and $*b*_{*i*}$ ($1 ≤ *a*_{*i*}, *b*_{*i*} ≤ *n*$, $*a*_{*i*} ≠ *b*_{*i*}$), which means that it is not possible to construct a road connecting cities $*a*_{*i*}$ and $*b*_{*i*}$. Consider the cities are numbered from 1 to $*n*$.

翻译中…

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

翻译中…

Output

翻译中…

You should print an integer $*s*$: the minimum number of roads that should be constructed, in the first line. Then $*s*$ lines should follow, each consisting of two integers $*a*_{*i*}$ and $*b*_{*i*}$ ($1 ≤ *a*_{*i*}, *b*_{*i*} ≤ *n*, *a*_{*i*} ≠ *b*_{*i*}$), which means that a road should be constructed between cities $*a*_{*i*}$ and $*b*_{*i*}$.

翻译中…

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

翻译中…

Note

翻译中…

This is one possible solution of the example:

翻译中…

image

翻译中…

These are examples of wrong solutions:

翻译中…

image

翻译中…

The above solution is wrong because it doesn't use the minimum number of edges (

翻译中…

4

翻译中…

vs

翻译中…

3

翻译中…

). In addition, it also tries to construct a road between cities

翻译中…

1

翻译中…

and

翻译中…

3

翻译中…

, while the input specifies that it is not allowed to construct a road between the pair.

翻译中…

image

翻译中…

The above solution is wrong because you need to traverse at least

翻译中…

3

翻译中…

roads to go from city

翻译中…

1

翻译中…

to city

翻译中…

3

翻译中…

, whereas in your country it must be possible to go from any city to another by traversing at most

翻译中…

2

翻译中…

roads.

翻译中…

image

翻译中…

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

翻译中…

1

翻译中…

to

翻译中…

3

翻译中…

,

翻译中…

2

翻译中…

to

翻译中…

3

翻译中…

, and

翻译中…

4

翻译中…

to

翻译中…

3

翻译中…

.

翻译中…

样例

Input #1
4 1
1 3
Output #1
3
1 2
4 2
2 3
InputCopy OutputCopy
题目信息
题号
330B
时间限制
2 s
内存限制
256 MB
标签
构造
图论

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。