【题目链接】: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. crm高速开发之OrganizationService

    这是主要的开发模式: /* 创建者:菜刀居士的博客  * 创建日期:2014年07月06号  */ namespace Net.CRM.OrganizationService {     using ...

  2. c14---排序,查找

    // // main.c // 冒泡排序 // // Created by xiaomage on 15/6/10. // Copyright (c) 2015年 xiaomage. All righ ...

  3. RBF网络——核心思想:把向量从低维m映射到高维P,低维线性不可分的情况到高维就线性可分了

      RBF网络能够逼近任意的非线性函数,可以处理系统内的难以解析的规律性,具有良好的泛化能力,并有很快的学习收敛速度,已成功应用于非线性函数逼近.时间序列分析.数据分类.模式识别.信息处理.图像处理. ...

  4. Svn install and use

    1.安装服务 使用yum安装subversion,简单.不繁琐. 1 yum install -y subversion 2.创建版本库 1 2       mkidr /svn/obj        ...

  5. 使用Micrisoft.net设计方案 第三章Web表示模式

    第三章Web表示模式 体系结构设计者在设计第一个作品时比较精简和干练.在第一次设计时,并清除自己做什么,因此比较小心谨慎.第二个作品是最危险的一个作品,此时他会对第一个作品做修饰和润色,以及把第一次设 ...

  6. jquery mobile datepicker

    1.http://jquerymobile.com/demos/1.0a4.1/experiments/ui-datepicker/ 这个只能用在iOS和PC上,使用<input date,An ...

  7. python 编码问题解决方案

    1.UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position 0: ordinal not in range(128) ...

  8. Qt与OpenCV结合:图像显示

    参考链接: http://www.cnblogs.com/emouse/archive/2013/03/29/2988717.html 注意:为了防止min max 问题,要把opencv的包含放在包 ...

  9. 6 Python+Selenium的元素定位方法(CSS)

    [环境] python3.6+selenium3.0.2+Firefox50.0+win7 [定位方法] 1.方法:find_element_by_css_selector('xx') CSS的语法比 ...

  10. MVC 接收文件

    [HttpPost] public ActionResult Layedit() { var files = Request.Files; //获得所上传的所有文件 ) { HttpPostedFil ...