【题目链接】:http://codeforces.com/contest/723/problem/E

【题意】



给你一个无向图;

让你把这m条边改成有向图;

然后使得出度数目等于入度数目的点的数目最多;

输出这个点的数目;

同时输出更改之后的所有有向边

【题解】



需要先明确;

就是图中度数为奇数的点的个数肯定是偶数个;

因为每条边都会贡献2度数;

所以最后的总度数肯定是偶数的;

则奇度数的点肯定得是偶数个,不然最后不会满足总度数为偶数;

知道这个之后;

猜想;

最后的答案就为原图中度数为偶数的点的个数;

为了保证方案存在;

我们新加一个编号为n+1的点;

然后把这个n+1号点和所有的原图中的度数为奇数的点全都连上边;

这个时候;

可以想见;

这n+1个点都是偶数度数的点了;

则可以走一个欧拉路径了;

对于欧拉路径来说;

每一个点,入度和出度的个数肯定是一样的;

只要把那些和n+1有关的边省略掉就好;

其他的直接输出;



【Number Of WA】



0



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x) typedef pair<int, int> pii;
typedef pair<LL, LL> pll; const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
const double pi = acos(-1.0);
const int N = 210; int t,n,m,du[N];
int G[N][N]; void dfs(int x)
{
rep1(y,1,n+1)
if (G[x][y])
{
if (x != n + 1 && y != n + 1)
cout << x << ' ' << y << endl;
G[x][y] = G[y][x] = 0;
dfs(y);
}
} int main()
{
//freopen("F:\\rush.txt", "r", stdin);
ios::sync_with_stdio(false), cin.tie(0);//scanf,puts,printf not use
cin >> t;
while (t--)
{
ms(du, 0),ms(G, 0);
cin >> n >> m;
int num1 = n;
rep1(i, 1, m)
{
int x, y;
cin >> x >> y;
G[x][y] = G[y][x] = 1;
du[x]++, du[y]++;
}
rep1(i, 1, n)
if (du[i] & 1)
G[n + 1][i] = G[i][n + 1] = 1, num1--;
cout << num1 << endl;
rep1(i, 1, n)
dfs(i);
}
return 0;
}

【codeforces 723E】One-Way Reform的更多相关文章

  1. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  2. 【codeforces 732F】Tourist Reform

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

  3. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  4. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  5. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  6. 【codeforces 709B】Checkpoints

    [题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...

  7. 【codeforces 709C】Letters Cyclic Shift

    [题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...

  8. 【Codeforces 429D】 Tricky Function

    [题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...

  9. 【Codeforces 670C】 Cinema

    [题目链接] http://codeforces.com/contest/670/problem/C [算法] 离散化 [代码] #include<bits/stdc++.h> using ...

随机推荐

  1. Win8下建立shortcut到開始界面

    在win8前建立開始菜单都非常easy,但到win8就有点不一样了.它的開始菜单是metro风格的.以下我们来看下详细的实现代码.有兴趣的朋友能够自己測试下,它的作用是设置shortcut到metro ...

  2. poj1426--Find The Multiple(广搜,智商题)

    Find The Multiple Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 18527   Accepted: 749 ...

  3. chrome 插件开发2

    登录 | 注册   基础文档 综述 调试 Manifest 文件 代码例子 模式匹配 分类索引 改变浏览器外观 Browser Actions 右键菜单 桌面通知 Omnibox 选项页 覆写特定页 ...

  4. ASP.NET Razor - C# and VB Code Syntax

    http://www.w3schools.com/aspnet/razor_syntax.asp Razor supports both C# (C sharp) and VB (Visual Bas ...

  5. linux IPtable防火墙 禁止和开放端口(转)

    linux IPtable防火墙 禁止和开放端口源:http://hi.baidu.com/zplllm/item/f910cb26b621db57c38d5983评: 1.关闭所有的 INPUT F ...

  6. 3.ThinkPHP入门---视图

    视图:MVC三大组成部分,负责信息的展示和输出 1.视图的创建 创建的位置需要是在分组目录下的view目录下余控制器同名的目录中. 2.视图的展示 在smarty和tinkphp都是使用diaplay ...

  7. /etc/rsyslog.conf配置文件说明

    一.authpriv.*                                      /var/log/secure 服务名称[连接符号]日志等级               日志记录位 ...

  8. let,const,var三者之间的区别

    在ES6中新增了两种定义变量的命令let和const,在这之前相信大家都对var定义变量很熟悉,那么在了解ES6方法前, 1.我们先来回顾一下var定义变量的方法. 下面来看这段代码: for (va ...

  9. python课程设计笔记(四)整数、浮点数与字符串 time库

    整数类型(范围无限制) 十进制1 -1 二进制0b1 -0b1 八进制0o1 -0o1 十六进制0x1 -0x1 浮点类型(范围有限制但可忽略) 运算存在不确定尾数 :0.1+0.2!=0.3 原因: ...

  10. java exception 异常错误记录

    //异常:Could not obtain transaction-synchronized Session for current thread 做定时器的时候用ApplicationContext ...