Codeforces Round #296 (Div. 1) C. Data Center Drama 欧拉回路
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
4 6
1 2
2 3
3 4
4 1
1 3
1 3
3 4
1 2
2 3
1 1
3 3
Sample Output
6
1 2
3 4
1 4
3 2
1 3
1 3
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 欧拉回路的更多相关文章
- Codeforces Round #469 (Div. 2) E. Data Center Maintenance
tarjan 题意: 有n个数据维护中心,每个在h小时中需要1个小时维护,有m个雇主,他们的中心分别为c1,c2,要求这两个数据中心不能同时维护. 现在要挑出一个数据中心的子集,把他们的维护时间都推后 ...
- Codeforces Round #296 (Div. 1) E. Triangles 3000
http://codeforces.com/contest/528/problem/E 先来吐槽一下,一直没机会进div 1, 马力不如当年, 这场题目都不是非常难,div 2 四道题都是水题! 题目 ...
- 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 ...
- 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 ...
- 字符串处理 Codeforces Round #296 (Div. 2) B. Error Correct System
题目传送门 /* 无算法 三种可能:1.交换一对后正好都相同,此时-2 2.上面的情况不可能,交换一对后只有一个相同,此时-1 3.以上都不符合,则不交换,-1 -1 */ #include < ...
- 水题 Codeforces Round #296 (Div. 2) A. Playing with Paper
题目传送门 /* 水题 a或b成倍的减 */ #include <cstdio> #include <iostream> #include <algorithm> ...
- CodeForces Round #296 Div.2
A. Playing with Paper 如果a是b的整数倍,那么将得到a/b个正方形,否则的话还会另外得到一个(b, a%b)的长方形. 时间复杂度和欧几里得算法一样. #include < ...
- 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 ...
- Codeforces Round #296 (Div. 2) A B C D
A:模拟辗转相除法时记录答案 B:3种情况:能降低2,能降低1.不能降低分别考虑清楚 C:利用一个set和一个multiset,把行列分开考虑.利用set自带的排序和查询.每次把对应的块拿出来分成两块 ...
随机推荐
- 基于消逝时间量的共识机制(POET)
来自于Intel project:Hyperledger Sawtooth,目前版本 PoET 1.0 PoET 其实是属于Nakamoto consenus的一种,利用“可信执行环境”来提高当前解决 ...
- unity 优秀开源项目
ihaiu.GUIDRef (查看项目资源使用情况) http://blog.ihaiu.com/unity-GUIDRef Ihaiu.PoolManager (对象池) http://github ...
- 记录一下mariadb设置主从同步的过程[虚拟机测试]
背景:因为工作的关系,需要找寻实时同步数据到另外系统的服务器的数据库上,查询下来,用mariadb进行跨服务器的同步数据动作,用主从同步比较多,也比较保险 也有使用shell脚本的,定时定候的执行my ...
- ActiveMQ之VirtualTopic是什么?
一句话总结: VirtualTopic是为了解决持久化模式下多消费端同时接收同一条消息的问题. 想象这样一个场景: 生产端产生了一笔订单,作为消息MessageOrder发了出去. 这笔订单既 ...
- 移动端默认meta标签
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><met ...
- win10 操作配置备忘
让程序自动启动 如果想要实现应用程序在所有的用户登录系统后都能自动启动,就把该应用程序的快捷方式放到"系统启动文件夹"里: C:\ProgramData\Microsoft\Win ...
- POJ 1141 Brackets Sequence(括号匹配二)
题目链接:http://poj.org/problem?id=1141 题目大意:给你一串字符串,让你补全括号,要求补得括号最少,并输出补全后的结果. 解题思路: 开始想的是利用相邻子区间,即dp[i ...
- Java事务管理之Hibernate
环境与版本 Hibernate 版本:Hibernate 4.2.2 (下载后的文件名为hibernate-release-4.2.2.Final.zip,解压目录hibernate-release- ...
- Redux-DevTools 安装
以下以Chrome为准. 首先,从Chrome Web Store(需要***支持)下载chrome 插件 Redux DevTools. 使用方式有两种: 一种只需在代码createStore中添加 ...
- GitHub正式启用声明
0x00 说明 GitHub账号很早之前就已经注册,几经常识都没有能够好好的将这座宝库应用好,实在是汗颜.今天特地将GitHub重新拾起,以后一定要好好使用这个利器,不要荒废了. 0x01 内容 Gi ...