CF9E.Interesting Graph and Apples

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Hexadecimal likes drawing. She has drawn many graphs already, both directed and not. Recently she has started to work on a still-life «interesting graph and apples». An undirected graph is called interesting, if each of its vertices belongs to one cycle only — a funny ring — and does not belong to any other cycles. A funny ring is a cycle that goes through all the vertices just once. Moreover, loops are funny rings too.

She has already drawn the apples and some of the graph edges. But now it is not clear, how to connect the rest of the vertices to get an interesting graph as a result. The answer should contain the minimal amount of added edges. And furthermore, the answer should be the lexicographically smallest one. The set of edges (x1,y1),(x2,y2),...,(xn,yn)(x_{1},y_{1}),(x_{2},y_{2}),...,(x_{n},y_{n}) , where xi<=yix_{i}<=y_{i} , is lexicographically smaller than the set (u1,v1),(u2,v2),...,(un,vn)(u_{1},v_{1}),(u_{2},v_{2}),...,(u_{n},v_{n}) , where ui<=viu_{i}<=v_{i} , provided that the sequence of integers x1,y1,x2,y2,...,xn,ynx_{1},y_{1},x_{2},y_{2},...,x_{n},y_{n} is lexicographically smaller than the sequence u1,v1,u2,v2,...,un,vnu_{1},v_{1},u_{2},v_{2},...,u_{n},v_{n} . If you do not cope, Hexadecimal will eat you. ...eat you alive.

有趣的图与苹果

Hexadecimal 喜欢绘画。她已经画了许多图形,既有有向图,也有无向图。最近,她开始着手制作一幅静物画《有趣的图形和苹果》。

一个无向图被称为有趣的,如果它的每个顶点只属于一个环 —— 一个有趣的环 —— 并且不属于任何其他环。一个有趣的环是一个通过所有顶点仅一次的环。此外,环中的自环也被认为是有趣的环。

她已经画了苹果和一些图的边。但现在不清楚如何连接剩下的顶点,以便得到一个有趣的图形。答案应包含最小数量的添加边。此外,答案应该是按字典顺序最小的。

边集合 (x1,y1),(x2,y2),...,(xn,yn)(x_1, y_1), (x_2, y_2), ..., (x_n, y_n),其中 xiyix_i ≤ y_i,按字典顺序小于边集合 (u1,v1),(u2,v2),...,(un,vn)(u_1, v_1), (u_2, v_2), ..., (u_n, v_n),其中 uiviu_i ≤ v_i,前提是整数序列 x1,y1,x2,y2,...,xn,ynx_1, y_1, x_2, y_2, ..., x_n, y_n 按字典顺序小于序列 u1,v1,u2,v2,...,un,vnu_1, v_1, u_2, v_2, ..., u_n, v_n

如果你无法解决,Hexadecimal 将会吃掉你... 生吃你。(翻译人认为:真有趣)

感谢Macw提供翻译

输入格式

The first line of the input data contains a pair of integers nn and mm ( 1<=n<=501<=n<=50 , 0<=m<=25000<=m<=2500 ) — the amount of vertices and edges respectively. The following lines contain pairs of numbers xix_{i} and yiy_{i} ( 1<=xi1<=x_{i} , yi<=ny_{i}<=n ) — the vertices that are already connected by edges. The initial graph may contain multiple edges and loops.

输入包含多行。
第一行输入两个整数 n,kn, k,分别代表图中点的数量和边的数量。其中 1n50,0k20501 \le n \le 50, 0 \le k \le 2050。接下来的 kk 行,每一行输入两个整数 x,yx, y,表示图中的初始边。(请注意,图中有可能出现自环的情况)

输出格式

In the first line output «YES» or «NO»: if it is possible or not to construct an interesting graph. If the answer is «YES», in the second line output kk — the amount of edges that should be added to the initial graph. Finally, output kk lines: pairs of vertices xjx_{j} and yjy_{j} , between which edges should be drawn. The result may contain multiple edges and loops. kk can be equal to zero

输出包含多行。
第一行输出YES或者NO,表示是否可以根据输入数据构造出一个有趣的图。
如果答案为YES,在第二行输出一个整数 kk,表示需要加入到初始图的数量。
接下来的 kk 行,每一行输出两个整数 x,yx, y,表示每一条边。(请注意,kk可以为零)

输入输出样例

  • 输入#1

    3 2
    1 2
    2 3
    

    输出#1

    YES
    1
    1 3
    

说明/提示

请注意,本题空间限制为64MB,是默认空间限制的二分之一。

首页