【题目链接】: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. hadoop-2.6.0集群开发环境配置

    hadoop-2.6.0集群开发环境配置 一.环境说明 1.1安装环境说明 本例中,操作系统为CentOS 6.6, JDK版本号为JDK 1.7,Hadoop版本号为Apache Hadoop 2. ...

  2. 【VC编程技巧】窗口☞3.6以渐变效果加载对话框

    平时我们常常能够看到非常多应用程序启动过程非常酷.什么百叶窗.渐变,各种效果,今天我们看一下怎样在程序中添加这样的效果. 一.演示样例展示: watermark/2/text/aHR0cDovL2Js ...

  3. hdu1716(库函数next_permutation)

    题目意思: 现有四张卡片,用这四张卡片能排列出非常多不同的4位数,要求按从小到大的顺序输出这些4位数. 注意首位没有前导0 pid=1716">http://acm.hdu.edu.c ...

  4. SICP 习题1.16-1.19体会

    首先反思一下, 昨天做1.14的时候犯了一个严重错误.思维定式了,导致花了非常多无用功. 1.14的关键是要想到2个物理意义. 一个是广度优先, 也就是仅仅考虑问题递归树的第一层子数.那么必定有公式 ...

  5. 【cl】找不到火狐Cannot find firefox binary in PATH

    org.openqa.selenium.WebDriverException: Cannot find firefox binary in PATH. Make sure firefox is ins ...

  6. iWatch报错: Authorization request cancled

    iWatch报错: Optional (Error Domin = com.apple.healthkit Code = 5 "Autherization request canceled& ...

  7. ssh 结构

    service:业务层 dao:数据訪问层 hibernate:持久层

  8. keyboard键盘demo

    main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:and ...

  9. Gerapy 使用详解

    https://blog.csdn.net/fengltxx/article/details/79894839

  10. Html Ajax上传文件,form表单下载文件

    Html中的代码: <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type&quo ...