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边的图,然后让你确定每条边的方向,使得入度=出度的点最多 . 度数为偶数的点均能满足入度 = 出度. 证明:度数为奇数的点有偶数个,奇度点两两配对连无向边,则新图存在欧拉回路,则可使新 ...
随机推荐
- Docker 容器学习笔记
Docker 诞生于2013年,最初发起者是dotCloud公司.Docker自开源后受到广泛的关注和讨论,目前已有多个相关项目逐渐形成了围绕Docker容器的生态体系,由于Docker在业界造成的影 ...
- 指针生成网络(Pointer-Generator-Network)原理与实战
指针生成网络(Pointer-Generator-Network)原理与实战 阅读目录 0 前言 1 Baseline sequence-to-sequence 2 Pointer-Generat ...
- MySQL 索引的优化
一.MySQL如何使用索引(index) 1.1 索引概述 索引用于快速查找具有特定列值的行. 如果不使用索引,MySQL必须从表的第一行开始,然后扫描整个表来寻找符合条件的行.这种情况下,表越大,扫 ...
- StoneTab标签页CAD插件 3.1.0
//////////////////////////////////////////////////////////////////////////////////////////////////// ...
- excel 导入
public static DataTable ExcelToDataTable(string fileName, string sheetName, bool isFirstRowColumn) { ...
- Qt使用自带的windeployqt 查找生成exe 必需的库文件
集成开发环境 QtCreator 目前生成图形界面程序 exe 大致可以分为两类:Qt Widgets Application 和 Qt Quick Application.下面分别介绍这两类exe ...
- spark2.0 DataSet操作的一些问题记录
随着新版本的Spark已经逐渐稳定,最近拟将原有框架升级到spark 2.0.还是比较兴奋的,特别是SQL的速度真的快了许多.. 然而,在其中一个操作时却卡住了.主要是dataframe.map操作, ...
- bootstrap-table的简单使用
先上效果图: 第一步:引用bootstrap-table的样式和js. @Styles.Render("~/assets/css/bootstrap.css") @Styles.R ...
- react——css样式
1.行内样式: 两个大括号包着.第一个大括号表示里面写js,第二个大括号里面是样式对象 2.传对象 将对象和结构分离,直接写一个大括号,里面写对象 3.将所有的样式对象合并成一个大对象,直接点 以上样 ...
- libusb移植
下载 https://sourceforge.net/projects/libusb/ 编译 # ./configure --build=i686-linux --host=arm-linux --p ...
