Description

There are n cities and m two-way roads in Berland, each road connects two cities. It is known that there is no more than one road connecting each pair of cities, and there is no road which connects the city with itself. It is possible that there is no way to get from one city to some other city using only these roads.

The road minister decided to make a reform in Berland and to orient all roads in the country, i.e. to make each road one-way. The minister wants to maximize the number of cities, for which the number of roads that begins in the city equals to the number of roads that ends in it.

Input

The first line contains a positive integer t (1 ≤ t ≤ 200) — the number of testsets in the input.

Each of the testsets is given in the following way. The first line contains two integers n and m (1 ≤ n ≤ 200, 0 ≤ m ≤ n·(n - 1) / 2) — the number of cities and the number of roads in Berland.

The next m lines contain the description of roads in Berland. Each line contains two integers u and v (1 ≤ u, v ≤ n) — the cities the corresponding road connects. It's guaranteed that there are no self-loops and multiple roads. It is possible that there is no way along roads between a pair of cities.

It is guaranteed that the total number of cities in all testset of input data doesn't exceed 200.

Pay attention that for hacks, you can only use tests consisting of one testset, so t should be equal to one.

Output

For each testset print the maximum number of such cities that the number of roads that begins in the city, is equal to the number of roads that ends in it.

In the next m lines print oriented roads. First print the number of the city where the road begins and then the number of the city where the road ends. If there are several answers, print any of them. It is allowed to print roads in each test in arbitrary order. Each road should be printed exactly once.

Example
Input
2
5 5
2 1
4 5
2 3
1 3
3 5
7 2
3 7
4 2
Output
3
1 3
3 5
5 4
3 2
2 1
3
2 4
3 7 正解:dfs+图论相关性质
解题报告:
  比赛的时候想到了度数为奇数的不可能成为答案,但是没想到答案个数就是度数为偶数的点的个数...
  因为度数为奇数的点不可能成为答案,那么我们可以发现利用奇数,我们去尽可能地满足偶数。因为如果我们想画出一条链,那么我们必须让路径的头尾都是度数为奇数的点,否则无法满足。
  我们这样把度数为奇数的点去掉之后,只剩下度数为偶数的点,根据图论相关性质,我们会发现此时一定存在一种方案使得每个点出度入度相等。直接连边就可以了。
 //It is made by jump~
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <ctime>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;
typedef long long LL;
const int inf = (<<);
const int MAXN = ;
const int MAXM = ;
int n,m,d[MAXN],ans;
int w[MAXN][MAXN];
int ea[MAXM],eb[MAXM],cnt; inline int getint()
{
int w=,q=; char c=getchar();
while((c<'' || c>'') && c!='-') c=getchar(); if(c=='-') q=,c=getchar();
while (c>='' && c<='') w=w*+c-'', c=getchar(); return q ? -w : w;
} inline void dfs(int x){
while(d[x]) {
for(int i=;i<=n;i++) {
if(!w[x][i]) continue;
w[x][i]=w[i][x]=; ea[++cnt]=x; eb[cnt]=i;
d[x]--; d[i]--; x=i; break;
}
}
} inline void work(){
int T=getint(); int x,y;
while(T--) {
n=getint(); m=getint(); memset(w,,sizeof(w)); memset(d,,sizeof(d));
for(int i=;i<=m;i++) {
x=getint(); y=getint();
w[x][y]=w[y][x]=;
d[x]++; d[y]++;
}
ans=n; cnt=;
for(int i=;i<=n;i++) if(d[i]&) ans--;
for(int i=;i<=n;i++) if(d[i]&) while(d[i]) dfs(i);
for(int i=;i<=n;i++) while(d[i]) dfs(i);
printf("%d\n",ans);
for(int i=;i<=cnt;i++) printf("%d %d\n",ea[i],eb[i]);
}
} int main()
{
work();
return ;
}

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

  1. 【codeforces 723E】One-Way Reform

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

  2. CodeForces 723E One-Way Reform

    构造. 有一种十分巧妙的方法可以使图中所有度数为偶数的节点,经过每条边定向后,出度和入度都相等. 首先统计每个节点的度数,将度数为奇数的节点与编号为$n+1$的节点连边,这样一来,这张新图变成了每个节 ...

  3. Codeforces 731C:Socks(并查集)

    http://codeforces.com/problemset/problem/731/C 题意:有n只袜子,m天,k个颜色,每个袜子有一个颜色,再给出m天,每天有两只袜子,每只袜子可能不同颜色,问 ...

  4. Codeforces 747D:Winter Is Coming(贪心)

    http://codeforces.com/problemset/problem/747/D 题意:有n天,k次使用冬天轮胎的机会,无限次使用夏天轮胎的机会,如果t<=0必须使用冬轮,其他随意. ...

  5. Codeforces 747C:Servers(模拟)

    http://codeforces.com/problemset/problem/747/C 题意:有n台机器,q个操作.每次操作从ti时间开始,需要ki台机器,花费di的时间.每次选择机器从小到大开 ...

  6. codeforces 723F : st-Spanning Tree

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

  7. codeforces 613D:Kingdom and its Cities

    Description Meanwhile, the kingdom of K is getting ready for the marriage of the King's daughter. Ho ...

  8. Codeforces 749D:Leaving Auction(set+二分)

    http://codeforces.com/contest/749/problem/D 题意:有几个人在拍卖场竞价,一共有n次喊价,有q个询问,每一个询问有一个num,接下来num个人从这次拍卖中除去 ...

  9. Codeforces 749B:Parallelogram is Back(计算几何)

    http://codeforces.com/problemset/problem/749/B 题意:已知平行四边形三个顶点,求另外一个顶点可能的位置. 思路:用向量来做. #include <c ...

随机推荐

  1. 如果动态设置json对象的key

    项目中要求动态设置json的key属性,如果按照一般的json设置方法是不行的.假如你把一个key设置为一个变量的话,那么最后js解析出来的就是key为这个变量名而不是这个变量的值. 解决:通过使用 ...

  2. img加载在IE11,chrome,FF下的不同

    IE11 img.complete 得不到img的大小,会使用img.onload chrome,ff:img.complete 得不到img的大小,会使用自己创建的img加载方法

  3. addShutdownHook的用法

    addShutdownHook作为一个正常关闭Java程序的途径,其实是非常有用的. 有JDK文档可知,当程序正常退出,或者为响应用户中断而终止虚拟机的时候,就会调用里面的线程,来作最后的退出处理. ...

  4. Apache下开启SSI配置使html支持include包含

    写页面的同学通常会遇到这样的烦恼,就是页面上的 html 标签越来越多的时候,寻找指定的部分就会很困难,那么能不能像 javascript 一样写在不同的文件中引入呢?答案是有的,apache 能做到 ...

  5. UWP 快速的Master/Detail实现

    最近在写快报(还没有写完)的过程中,一开始就遇到了这个Master/Detail如何实现的问题. 微软给出Demo并不符合要求,搜索后找到了今日头条开发者写的一篇 :实现Master/Detail布局 ...

  6. gulp插件gulp-usemin简单使用

    关于什么是gulp,它和grunt有什么区别等问题,这里不做任何介绍.本文主要介绍如何使用gulp-usemin这款插件,同时也会简单介绍本文中用到的一些插件. 什么是gulp-usemin 用来将H ...

  7. 移动OA,致我们终将逝去的青春(程序员版)[转]

    移动OA和致青春有什么关系,难道说赵薇也来做手机应用了?为什么不行,当年小燕子代言的打印机可是红火的很,现在再秀一把时尚手机办公也未必不可啊.言归正转,本文还是以点代面阐述移动OA开发过程,但是,它的 ...

  8. 如何批量删除虚拟机及其关联的存储(Windows Azure)

    可以通过运行附件中PowerShell脚本文件RemoveVMandDisk.ps1批量删除VM和Disk,详细代码如下: param($serviceName) echo "Startin ...

  9. 路由信息协议(RIP)的防环机制

    防环机制 1-记数最大值(maximum hop count):定义最大跳数(最大为15跳),当跳数为16跳时,目标为不可达. 2-水平分割(split horizon):从一个接口学习到的路由不会再 ...

  10. jquery总结

    id选择器只能选定第一个满足条件的元素 class选择器可以选定一类满足条件的元素 text(),html(),val(),attr()等操作类型的函数,作用对象是前面选择器选定的元素.选定的元素可能 ...