CF45H.Road Problem

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

The Berland capital (as you very well know) contains n junctions, some pairs of which are connected by two-way roads. Unfortunately, the number of traffic jams in the capital has increased dramatically, that's why it was decided to build several new roads. Every road should connect two junctions.

The city administration noticed that in the cities of all the developed countries between any two roads one can drive along at least two paths so that the paths don't share any roads (but they may share the same junction). The administration decided to add the minimal number of roads so that this rules was fulfilled in the Berland capital as well. In the city road network should exist no more than one road between every pair of junctions before or after the reform.

贝兰德首都(您非常清楚)包含 nn 个路口,其中某些路口对之间由双向道路连接。不幸的是,首都的交通拥堵数量急剧增加,因此决定修建若干条新道路。每条新道路必须连接两个路口。

市政府注意到,在所有发达国家的城市中,任意两个路口之间均存在至少两条路径可通行,且这两条路径不共享任何道路(但可以经过相同的路口)。市政府决定新增最少数量的道路,使得贝兰德首都的道路网络也满足这一规则。此外,无论在改革前还是改革后,任意两个路口之间至多只能存在一条道路。

输入格式

The first input line contains a pair of integers n, m (2 ≤ n ≤ 900, 1 ≤ m ≤ 100000), where n is the number of junctions and m is the number of roads. Each of the following m lines contains a description of a road that is given by the numbers of the connected junctions a__i, b__i (1 ≤ a__i, b__i ≤ n, a__i ≠ b__i). The junctions are numbered from 1 to n. It is possible to reach any junction of the city from any other one moving along roads.

第一行输入包含两个整数 nnmm2n9002 \leq n \leq 9001m1000001 \leq m \leq 100000),其中 nn 表示路口的数量,mm 表示道路的数量。接下来的 mm 行每行描述一条道路,由其所连接的两个路口编号 aia_ibib_i1ai,bin1 \leq a_i, b_i \leq n,且 aibia_i \neq b_i)给出。路口编号为 11nn。城市中任意两个路口之间均可通过道路相互到达。

输出格式

On the first line print t — the number of added roads. Then on t lines print the descriptions of the added roads in the format of the input data. You can use any order of printing the roads themselves as well as the junctions linked by every road. If there are several solutions to that problem, print any of them.

If the capital doesn't need the reform, print the single number 0.

If there's no solution, print the single number -1.

第一行输出 t —— 新增道路的数量。随后的 t 行中,按输入数据的格式输出所添加道路的描述。每条道路中两个路口的顺序,以及所有道路本身的输出顺序均可任意。若该问题存在多种解法,输出其中任意一种即可。

如果首都无需进行改造,则仅输出单个数字 0。

若无解,则仅输出单个数字 -1。

输入输出样例

  • 输入#1

    4 3
    1 2
    2 3
    3 4

    输出#1

    1
    1 4
  • 输入#2

    4 4
    1 2
    2 3
    2 4
    3 4

    输出#2

    1
    1 3

输入解题思路,AI测评打分。不知道怎么写?

首页