codeforces723E
One-Way Reform
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 tshould 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
2
5 5
2 1
4 5
2 3
1 3
3 5
7 2
3 7
4 2
3
1 3
3 5
5 4
3 2
2 1
3
2 4
3 7 sol:
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=;
int T,n,m,Deg[N],In[N],Out[N];
set<int>E[N],Ans[N];
bool Bo[N][N],Vis[N];
inline void Link(int x,int y)
{
E[x].insert(y); Bo[x][y]=; Deg[x]++;
}
inline void dfs(int x)
{
// cout<<"x="<<x<<endl;
Vis[x]=;
set<int>::iterator it;
for(it=E[x].begin();it!=E[x].end();it++)
{
int to=*it;
if(!Bo[x][to]) continue;
Bo[x][to]=Bo[to][x]=;
Ans[x].insert(to);
dfs(to);
}
}
int main()
{
// freopen("data.in","r",stdin);
int i;
R(T);
while(T--)
{
R(n); R(m);
for(i=;i<=n;E[i].clear(),Ans[i].clear(),Deg[i]=In[i]=Out[i]=Vis[i]=,i++);
for(i=;i<=m;i++)
{
int x,y; R(x); R(y); Link(x,y); Link(y,x);
}
for(i=;i<=n;i++) if(Deg[i]&) Link(n+,i),Link(i,n+);
for(i=;i<=n;i++) if(!Vis[i]) dfs(i);
set<int>::iterator it;
for(i=;i<=n;i++)
{
for(it=Ans[i].begin();it!=Ans[i].end();it++)
{
if(*it!=n+) In[*it]++,Out[i]++;
}
}
int Sum=;
for(i=;i<=n;i++) if(In[i]==Out[i]) Sum++;
Wl(Sum);
for(i=;i<=n;i++)
{
for(it=Ans[i].begin();it!=Ans[i].end();it++) if(*it!=n+)
{
W(i); Wl(*it);
}
}
}
return ;
}
/*
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
*/
codeforces723E的更多相关文章
- Codeforces723E One-Way Reform【欧拉回路】
题意:给你n点m边的图,然后让你确定每条边的方向,使得入度=出度的点最多 . 度数为偶数的点均能满足入度 = 出度. 证明:度数为奇数的点有偶数个,奇度点两两配对连无向边,则新图存在欧拉回路,则可使新 ...
随机推荐
- SysInternals提供了一个工具RamMap,可以查看内存的具体使用情况
SysInternals提供了一个工具RamMap,可以查看内存的具体使用情况.如果发现是Paged Pool和Nonpaged Pool占用过大,可以用另一个工具poolmon来查看占用内存的驱动T ...
- MQTT协议探究(三)
1 回顾与本次目标 1.1 回顾 主题通配符 主题语义和用法 WireShark进行抓包分析了报文 报文分析: SUBSCRIBE--订阅主题 SUBACK--订阅确认 UNNSUBSCRIBE--取 ...
- 【原创】编程基础之Jekins
Jenkins 2.164.2 官方:https://jenkins.io 一 简介 Build great things at any scale The leading open source a ...
- javaIO——PipedReader & PipedWriter
1. 概述: PipedReader 和 PipedWriter,意为管道读写流.所谓管道,那就是有进有出,所以这也是它们跟其它流对象最显著的区别:PipedReader和PipedWriter必须成 ...
- 【php设计模式】享元模式
享元模式其实就是共享独享模式,减少重复实例化对象的操作,从而将实例化对象造成的内存开销降到最低. 享元模式尝试重用现有的同类对象,如果未找到匹配的对象,则创建新对象.我们将通过创建 5 个对象来画出 ...
- DX使用随记--其他
1. 百分号显示格式 百分号:{0:P}表示显示为百分号模式.如数据源中为0.5.表示出来为50%
- Delphi Tobject类
- 前端基础(七):Toastr(弹出框)
Toastr 简介 jquery toastr 一款轻量级的通知提示框插件. 网页开发中经常会用到提示框,自带的alert样式无法调整,用户体验差. 所以一般通过自定义提示框来实现弹窗提示信息,而jq ...
- AGC刷题记
已经刷不了几天了... AGC001 A-BBQ Easy 排个序就过了 B-Mysterious Light 手膜一下,你会发现魔改一下\(gcd\)就行了 C-Shorten Diameter 刚 ...
- kettle 数据抽取时会出现 无法插入NULL
kettle 数据抽取时会出现 无法插入NULL,其实是空字符串,原因是kettle默认不区分空字符串和NULL. 解决办法: 修改kettle.properties 文件: