Codeforces Round #296 (Div. 1)C. Data Center Drama

Time Limit: 2 Sec  Memory Limit: 256 MB
Submit: xxx  Solved: 2xx

题目连接

http://codeforces.com/contest/528/problem/C

Description

The project of a data center of a Big Software Company consists of n computers connected by m cables. Simply speaking, each computer can be considered as a box with multiple cables going out of the box. Very Important Information is transmitted along each cable in one of the two directions. As the data center plan is not yet approved, it wasn't determined yet in which direction information will go along each cable. The cables are put so that each computer is connected with each one, perhaps through some other computers.

The person in charge of the cleaning the data center will be Claudia Ivanova, the janitor. She loves to tie cables into bundles using cable ties. For some reasons, she groups the cables sticking out of a computer into groups of two, and if it isn't possible, then she gets furious and attacks the computer with the water from the bucket.

It should also be noted that due to the specific physical characteristics of the Very Important Information, it is strictly forbidden to connect in one bundle two cables where information flows in different directions.

The management of the data center wants to determine how to send information along each cable so that Claudia Ivanova is able to group all the cables coming out of each computer into groups of two, observing the condition above. Since it may not be possible with the existing connections plan, you are allowed to add the minimum possible number of cables to the scheme, and then you need to determine the direction of the information flow for each cable (yes, sometimes data centers are designed based on the janitors' convenience...)

Input

The first line contains two numbers, n and m (1 ≤ n ≤ 100 000, 1 ≤ m ≤ 200 000) — the number of computers and the number of the already present cables, respectively.

Each of the next lines contains two numbers ai, bi (1 ≤ ai, bi ≤ n) — the indices of the computers connected by the i-th cable. The data centers often have a very complex structure, so a pair of computers may have more than one pair of cables between them and some cables may connect a computer with itself.

Output

In the first line print a single number p (p ≥ m) — the minimum number of cables in the final scheme.

In each of the next p lines print a pair of numbers ci, di (1 ≤ ci, di ≤ n), describing another cable. Such entry means that information will go along a certain cable in direction from ci to di.

Among the cables you printed there should be all the cables presented in the original plan in some of two possible directions. It is guaranteed that there is a solution where p doesn't exceed 500 000.

If there are several posible solutions with minimum possible value of p, print any of them.

Sample Input

Input
4 6
1 2
2 3
3 4
4 1
1 3
1 3
 
Input
3 4
1 2
2 3
1 1
3 3

Sample Output

Output
6
1 2
3 4
1 4
3 2
1 3
1 3
Output
6
2 1
2 3
1 1
3 3
3 1
1 1

HINT

Picture for the first sample test. The tied pairs of cables are shown going out from the same point.

Picture for the second test from the statement. The added cables are drawin in bold.

Alternative answer for the second sample test:

题意:

就是给你一个无向图,然后这些无向图的边,可以转化成一个有向图的边,问你怎么加最少的边,使得每一个点的出度等于入度,输出边数和边集

题解:

首先,我们把所有的无向边都建好,然后如果某一个点的出度是奇数的话,那么我们就依次连接奇数的点

比如 1,2,3的出度是奇数,那么我们就连 1->2,2->3,3->1,这样子就修正好了,就全是偶数啦

然后我们就DFS,来构造欧拉回路!

然后就乌拉拉的跑就是了,如果跑完还是奇数的话,那就随便给一个点加一个自环就好啦~

~\(≧▽≦)/~啦啦啦,这道题完啦

代码:

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 500001
#define mod 10007
#define eps 1e-9
//const int inf=0x7fffffff; //无限大
const int inf=0x3f3f3f3f;
/* */
//************************************************************************************** inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int n,m;
multiset<int> e[maxn];
int out[maxn];
int cnt=;
int a[maxn];
int all;
int ans[maxn];
void dfs(int x)
{
while(!e[x].empty())
{
int i=*(e[x].begin());
e[x].erase(e[x].begin());
e[i].erase(e[i].find(x));
dfs(i);
}
ans[++all]=x;
}
int main()
{
n=read(),m=read();
while(m--)
{
int x=read(),y=read();
e[x].insert(y);
e[y].insert(x);
out[x]++;
out[y]++;
cnt++;
}
int tot=;
for(int i=;i<=n;i++)
{
if(out[i]%==)
a[++tot]=i;
}
for(int i=;i<tot;i+=)
{
e[a[i]].insert(a[i+]);
e[a[i+]].insert(a[i]);
cnt++;
}
if(cnt%)
cnt++;
printf("%d\n",cnt);
all=;
dfs();
for(int i=;i<all;i++)
{
if(i%)
printf("%d %d\n",ans[i],ans[i+]);
else
printf("%d %d\n",ans[i+],ans[i]);
}
if(all%==)
printf("1 1\n");
}

Codeforces Round #296 (Div. 1) C. Data Center Drama 欧拉回路的更多相关文章

  1. Codeforces Round #469 (Div. 2) E. Data Center Maintenance

    tarjan 题意: 有n个数据维护中心,每个在h小时中需要1个小时维护,有m个雇主,他们的中心分别为c1,c2,要求这两个数据中心不能同时维护. 现在要挑出一个数据中心的子集,把他们的维护时间都推后 ...

  2. Codeforces Round #296 (Div. 1) E. Triangles 3000

    http://codeforces.com/contest/528/problem/E 先来吐槽一下,一直没机会进div 1, 马力不如当年, 这场题目都不是非常难,div 2 四道题都是水题! 题目 ...

  3. Codeforces Round #296 (Div. 2) D. Clique Problem [ 贪心 ]

    传送门 D. Clique Problem time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  4. Codeforces Round #296 (Div. 2) C. Glass Carving [ set+multiset ]

    传送门 C. Glass Carving time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  5. 字符串处理 Codeforces Round #296 (Div. 2) B. Error Correct System

    题目传送门 /* 无算法 三种可能:1.交换一对后正好都相同,此时-2 2.上面的情况不可能,交换一对后只有一个相同,此时-1 3.以上都不符合,则不交换,-1 -1 */ #include < ...

  6. 水题 Codeforces Round #296 (Div. 2) A. Playing with Paper

    题目传送门 /* 水题 a或b成倍的减 */ #include <cstdio> #include <iostream> #include <algorithm> ...

  7. CodeForces Round #296 Div.2

    A. Playing with Paper 如果a是b的整数倍,那么将得到a/b个正方形,否则的话还会另外得到一个(b, a%b)的长方形. 时间复杂度和欧几里得算法一样. #include < ...

  8. Codeforces Round #296 (Div. 2) A. Playing with Paper

    A. Playing with Paper One day Vasya was sitting on a not so interesting Maths lesson and making an o ...

  9. Codeforces Round #296 (Div. 2) A B C D

    A:模拟辗转相除法时记录答案 B:3种情况:能降低2,能降低1.不能降低分别考虑清楚 C:利用一个set和一个multiset,把行列分开考虑.利用set自带的排序和查询.每次把对应的块拿出来分成两块 ...

随机推荐

  1. C/C++杂记:NULL与0的区别、nullptr的来历

    某些时候,我们需要将指针赋值为空指针,以防止野指针.   有人喜欢使用NULL作为空指针常量使用,例如:int* p = NULL;. 也有人直接使用0值作为空指针常量,例如:int* p = 0;. ...

  2. Django中HttpRequest和HttpResponse

    请求和响应对象 Django中通过使用请求和响应对象来传递系统的状态. 当请求一个页面的时候,Django就创建一个HttpRequest对象,它包含了关于请求的元数据对象,然后Django加载适当的 ...

  3. 18 A GIF decoder: an exercise in Go interfaces 一个GIF解码器:go语言接口训练

    A GIF decoder: an exercise in Go interfaces  一个GIF解码器:go语言接口训练 25 May 2011 Introduction At the Googl ...

  4. centos7联网

    一般centos安装(在虚拟机上安装)完成后需要自己配置服务,下面我就讲下如何配置 配置联网步骤 首先,打开虚拟机的两个服务,右击我的电脑-->管理--->找到服务-->右击启动 两 ...

  5. 接口测试工具--Poster与Postman的简单实用

    HTTP/SOAP协议接口的功能测试: 1.浏览器URL(GET请求) http://127.0.0.1:8000/login/?username=zhangsan&password=1234 ...

  6. 聚类:(K-means)算法

    1.归类: 聚类(clustering) 属于非监督学习 (unsupervised learning) 无类别标记(class label) 2.举例: 3. K-means 算法:         ...

  7. **汇总CodeIgniter(CI)的数据库操作函数

    //查询: $query = $this->db_query("SELECT * FROM table"); ================================ ...

  8. Hive(九)Hive 执行过程实例分析

    一.Hive 执行过程概述 1.概述 (1) Hive 将 HQL 转换成一组操作符(Operator),比如 GroupByOperator, JoinOperator 等 (2)操作符 Opera ...

  9. LoadRunner常用知识点-----LoadRunner日志输出

    在Windows环境下,日志文件output.txt保存在脚本目录中:在UNIX环境下,保存在标准输出中. [Vuser]——[Run Time Settings]——[General]——[Log] ...

  10. Bootstrap进阶二:基本组件

    基本组件是Bootstrap的精华之一,其中都是开发者平时需要用到的交互组件.例如:网站导航.标签页.工具条.面包屑.分页栏.提示标签.产品展示.提示信息块和进度条等.这些组件都配有jQuery插件, ...