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边的图,然后让你确定每条边的方向,使得入度=出度的点最多 . 度数为偶数的点均能满足入度 = 出度. 证明:度数为奇数的点有偶数个,奇度点两两配对连无向边,则新图存在欧拉回路,则可使新 ...
随机推荐
- Python中的with语句(上下文管理协议)
在平时工作中总会有这样的任务,它们需要开始前做准备,然后做任务,然后收尾清理....比如读取文件,需要先打开,读取,关闭 这个时候就可以使用with简化代码,很方便 1.没有用with语句 f = o ...
- Dubbo相关的基础
Dubbo是一款高性能轻量级的java RPC框架,它提供了三大核心能力:面向接口的远程方法调用,智能容错和负载均衡,以及服务注册与发现. Dubbo是阿里开源的一个项目,现在已经是Apache的顶级 ...
- Jerry眼中的SAP客户数据模型
本文Jerry将介绍八款SAP产品中的客户模型.希望您在阅读完本文之后,能对SAP客户模型设计的思路有一个最最粗浅的了解. 由于Jerry水平和精力所限,本文不会详细阐述这些产品里的客户模型设计细节, ...
- ASE19团队项目alpha阶段model组 scrum11 记录
本次会议于11月15日,19时整在微软北京西二号楼sky garden召开,持续5分钟. 与会人员:Jiyan He, Kun Yan, Lei Chai, Linfeng Qi, Xueqing W ...
- Spring Cloud(一)服务的注册与发现(Eureka)
Spring Cloud是一个基于Spring Boot实现的云应用开发工具,它为基于JVM的云应用开发中涉及的配置管理.服务发现.断路器.智能路由.微代理.控制总线.全局锁.决策竞选.分布式会话和集 ...
- 【Struts2】拦截器
一.概述 二.在Struts2中使用拦截器 2.1 步骤 2.2 分析拦截器原理 2.3 关于interceptor与Filter区别: 三.案例 一.概述 介绍拦截器: struts2拦截器使用的是 ...
- 第七章、Ajango自带auth模块
目录 第七章.Ajango自带auth模块 一.什么是auth auth是django自带的用户认证模块 二.auth模块的常用方法 三.拓展默认的auth_user表 第七章.Ajango自带aut ...
- Win10系统Edge浏览器怎么截取网页长图?
有时我们在工作演示时会需要截取网页上的图片,不过简单的截图可以,但如果需要截取超过屏幕大小的整个网页,你是不是就有些束手无策了.虽然拼接图片也是种方法,但毕竟还是不方便,下面好系统重装助手就教你在Wi ...
- PhpStorm添加PHP代码规范检查CodeSniffer(phpcs)和PHP代码静态分析工具Mess Detector(phpmd)
一.安装 添加镜像,加速下载 ./composer.phar config -g repo.packagist composer https://packagist.phpcomposer.com ...
- 不创建父窗体的情况下他其他窗体的信息显示在第一个打开的窗体!(winfrom)
公司使用vs2008做的东西,用vs2017都打不开了(编译错误) 叫我更新一下,我看了一下,08的项目 和 winform 差不多 如何就用winfrom来做了 (winform 很久没碰了,, ...