构造。

有一种十分巧妙的方法可以使图中所有度数为偶数的节点,经过每条边定向后,出度和入度都相等。

首先统计每个节点的度数,将度数为奇数的节点与编号为$n+1$的节点连边,这样一来,这张新图变成了每个节点的度数都是偶数的图,必然存在欧拉回路。任意一条欧拉回路都使得原图中度数为偶数的节点的出度与入度相等。

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<ctime>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
char c = getchar();
x = ;
while(!isdigit(c)) c = getchar();
while(isdigit(c))
{
x = x * + c - '';
c = getchar();
}
} int T,n,m,ans,cnt;
vector<int>v[];
int f[];
int ss[],ee[],t[][],p[][]; void dfs(int x)
{
for(int i=v[x].size()-;i>=;i--)
{
if(t[x][v[x][i]]==) continue; t[x][v[x][i]]=t[v[x][i]][x]=;
ss[cnt]=x; ee[cnt]=v[x][i]; cnt++; dfs(v[x][i]);
}
} int main()
{
cin>>T;
for(int cas=;cas<=T;cas++)
{
cin>>n>>m; for(int i=;i<=n+;i++) v[i].clear(); memset(f,,sizeof f);
memset(p,,sizeof p); for(int i=;i<=m;i++)
{
int a,b; cin>>a>>b; v[a].push_back(b);
v[b].push_back(a);
f[a]++; f[b]++;
p[a][b]=p[b][a]=;
} ans=; vector<int>x;
for(int i=;i<=n;i++)
{
if(f[i]%==) ans++;
else x.push_back(i);
} for(int i=;i<x.size();i++)
{
v[n+].push_back(x[i]);
v[x[i]].push_back(n+);
} memset(t,,sizeof t); cnt=;
for(int i=;i<=n+;i++) dfs(i); printf("%d\n",ans); for(int i=;i<m+(n-ans);i++)
{
if(p[ss[i]][ee[i]]==)
printf("%d %d\n",ss[i],ee[i]);
} }
return ;
}

CodeForces 723E One-Way Reform的更多相关文章

  1. codeforces 723E:One-Way Reform

    Description There are n cities and m two-way roads in Berland, each road connects two cities. It is ...

  2. 【codeforces 723E】One-Way Reform

    [题目链接]:http://codeforces.com/contest/723/problem/E [题意] 给你一个无向图; 让你把这m条边改成有向图; 然后使得出度数目等于入度数目的点的数目最多 ...

  3. codeforces 723E (欧拉回路)

    Problem One-Way Reform 题目大意 给一张n个点,m条边的无向图,要求给每条边定一个方向,使得最多的点入度等于出度,要求输出方案. 解题分析 最多点的数量就是入度为偶数的点. 将入 ...

  4. codeforces 659E E. New Reform(图论)

    题目链接: E. New Reform time limit per test 1 second memory limit per test 256 megabytes input standard ...

  5. 【codeforces 732F】Tourist Reform

    [题目链接]:http://codeforces.com/contest/732/problem/F [题意] 给你一张无向图; n个点,m条边; 让你把这张图改成有向边 然后定义r[i]为每个点能够 ...

  6. Codeforces 723e [图论][欧拉回路]

    /* 不要低头,不要放弃,不要气馁,不要慌张. 题意: 给你一个有n个点,m条边的无向图,给每条边规定一个方向,使得这个图变成有向图,并且使得尽可能多的点入度与出度相同. 输出有多少个这样的点并且输出 ...

  7. codeforces723E

    One-Way Reform CodeForces - 723E There are n cities and m two-way roads in Berland, each road connec ...

  8. Codeforces Round #375 (Div. 2) E. One-Way Reform 欧拉路径

    E. One-Way Reform 题目连接: http://codeforces.com/contest/723/problem/E Description There are n cities a ...

  9. Codeforces Round #346 (Div. 2) E. New Reform dfs

    E. New Reform 题目连接: http://www.codeforces.com/contest/659/problem/E Description Berland has n cities ...

随机推荐

  1. webpack插件url-loader使用规范

    其实说到性能优化,他的范围太广了,今天我们就只聊一聊通过webpack配置减少http请求数量这个点吧. 简单说下工作中遇到的问题吧,我们做的一个项目中首页用了十多张图片,每张图片都是一个静态资源,所 ...

  2. 【PHP】Windows下配置用mail()发送邮件

    ZZ:解决windows系统下php.ini邮件配置正确不发送邮件的问题 php mail()函数在windows不能用,需要安装sendmail,假如是用的XAMPP,则已经下载好,不需要重新下载~ ...

  3. WCF使用注意事项

    执行如下 批处理:"C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\svcutil.exe" http://127.0.0.1: ...

  4. WP8.1 Windows Phone 8.1开发:何如定义Pivot头部样式、定义Pivot头部颜色

    Windows Phone 8.1 ,如何自定义Pivot头部样式?用Pivot控件完成这样的效果. 网上找了好久,只找到了windows phone 8的解决方案. 终于一个大神给支了招,我觉得我有 ...

  5. python学习笔记(一)之为什么学习python

    python的特点: 跨平台 实现同一个功能是Java代码的1/5 python应用范围: 操作系统 web 3D动画 企业应用 云计算 如何学习python? 学习语法 验证例子 学会总结 课外实践

  6. Linux中关机,重启,注销命令

    关机: shutdown -h now  #立刻关机重启,工作中常用 shutdown -h +1    #1分钟后关机 init 0 halt                        #立即停 ...

  7. 逃生(HDU4857 + 反向拓扑排序)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4857 题面是中文题面,就不解释题意了,自己点击链接去看下啦~这题排序有两个条件,一个是按给定的那个序列 ...

  8. Chrome 浏览器 autocomplete off无效

    在表单填写时突然发现autocomplete 失效了 网上搜索后得出大概意思是在某些情况下确实无效[捂脸] 解决方案 大致原因是浏览器默认为type为password的input标签自动填充密码 这样 ...

  9. windows下安装python过程

    方法一:如果你的电脑没有安装python,推荐使用anaconda(自带python环境,同时自带各种第三方库,可以省去很多麻烦) 这里提供两个下载地址:1,.官网https://www.anacon ...

  10. python基础===获取知乎标题时候,文件编码失败的总结

    总结一下,关于获取到的信息编码失败. 刚才在执行代码的时候,发现一个问题: 然后修改代码如下: '''爬取知乎界面的标题''' import requests import re import sys ...