题目链接:传送门

题目大意:一副无向图,要求你给边定向(变为有向图),使出度等于入度的点最多,输出有多少

     个点,并且输出定向后的边(前为起点,后为终点)

题目思路:欧拉路

     我们这样考虑,先考虑无向图的点的度数,如果为奇数则一定无法变为题目要求的点,ans-1

     对于度为偶数的点则一定可以通过调整满足。

处理方法:新建一个虚拟节点0,使所有度为奇数的点向其连一条边,那么最终图中的点的度数都为偶数。

     这样就满足欧拉路的条件了。我们只需要跑欧拉路并且将走过的路径保留下来即可。

     注意将与虚拟节点连的边删去。

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <stack>
#include <cctype>
#include <queue>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <climits>
#define lson rt<<1,l,mid
#define rson rt<<1|1,mid+1,r
#define fi first
#define se second
#define ping(x,y) ((x-y)*(x-y))
#define mst(x,y) memset(x,y,sizeof(x))
#define mcp(x,y) memcpy(x,y,sizeof(y))
using namespace std;
#define gamma 0.5772156649015328606065120
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define N 50005
#define maxn 30010
typedef pair<int,int> PII;
typedef long long LL;
LL read(){
LL x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=(x<<)+(x<<)+ch-'';ch=getchar();}
return x*f;
} int n,m,k,ans,in[];
int vis[][];
set<int>S[];
vector<PII >V;
void dfs(int u){
while(S[u].size()){
int x=*S[u].begin();S[u].erase(S[u].begin());
if(vis[u][x])continue;
vis[u][x]=vis[x][u]=;
V.push_back(make_pair(u,x));
dfs(x);
}
}
int main(){
int i,j,group,x,y,v,Case=;
group=read();
while(group--){
n=read(),m=read();
mst(in,);V.clear();
mst(vis,);
for(i=;i<=n;++i) S[i].clear();
for(i=;i<=m;++i){
x=read(),y=read();
S[x].insert(y),S[y].insert(x);
++in[x],++in[y];
}
int ans=n;
for(i=;i<=n;++i)if(in[i]&){
--ans;
S[].insert(i),S[i].insert();
}
for(i=;i<=n;++i)
if(S[i].size())
dfs(i);
printf("%d\n",ans);
for(PII u:V)if(u.fi!=&&u.se!=){
printf("%d %d\n",u.fi,u.se);
}
}
return ;
}

Codeforces Round #375 (Div. 2)E. One-Way Reform的更多相关文章

  1. Codeforces Round #375 (Div. 2) - D

    题目链接:http://codeforces.com/contest/723/problem/D 题意:给定n*m小大的字符矩阵.'*'表示陆地,'.'表示水域.然后湖的定义是:如果水域完全被陆地包围 ...

  2. Codeforces Round #375 (Div. 2) - C

    题目链接:http://codeforces.com/contest/723/problem/C 题意:给定长度为n的一个序列.还有一个m.现在可以改变序列的一些数.使得序列里面数字[1,m]出现次数 ...

  3. Codeforces Round #375 (Div. 2) - B

    题目链接:http://codeforces.com/contest/723/problem/B 题意:给定一个字符串.只包含_,大小写字母,左右括号(保证不会出现括号里面套括号的情况),_分隔开单词 ...

  4. Codeforces Round #375 (Div. 2) - A

    题目链接:http://codeforces.com/contest/723/problem/A 题意:在一维坐标下有3个人(坐标点).他们想选一个点使得他们3个到这个点的距离之和最小. 思路:水题. ...

  5. Codeforces Round #375 (Div. 2) F. st-Spanning Tree 生成树

    F. st-Spanning Tree 题目连接: http://codeforces.com/contest/723/problem/F Description You are given an u ...

  6. Codeforces Round #375 (Div. 2) E. One-Way Reform 欧拉路径

    E. One-Way Reform 题目连接: http://codeforces.com/contest/723/problem/E Description There are n cities a ...

  7. Codeforces Round #375 (Div. 2) D. Lakes in Berland 贪心

    D. Lakes in Berland 题目连接: http://codeforces.com/contest/723/problem/D Description The map of Berland ...

  8. Codeforces Round #375 (Div. 2) B. Text Document Analysis 模拟

    B. Text Document Analysis 题目连接: http://codeforces.com/contest/723/problem/B Description Modern text ...

  9. Codeforces Round #375 (Div. 2) A. The New Year: Meeting Friends 水题

    A. The New Year: Meeting Friends 题目连接: http://codeforces.com/contest/723/problem/A Description There ...

  10. Codeforces Round #375 (Div. 2) Polycarp at the Radio 优先队列模拟题 + 贪心

    http://codeforces.com/contest/723/problem/C 题目是给出一个序列 a[i]表示第i个歌曲是第a[i]个人演唱,现在选出前m个人,记b[j]表示第j个人演唱歌曲 ...

随机推荐

  1. Android Wear Preview- 归档通知(Stacking Notifications)

    ---------------------------------------------------------------------------------------------------- ...

  2. ORACLE11G 字符集更改(这里更改为AL32UTF8)

    ORACLE11G 字符集更改(这里更改为AL32UTF8)更改步骤:1.用sysdba角色用户登录sqlplus: 命令行输入:sqlplus sys as sysdba 2.输入口令,进入sqlp ...

  3. Application.idle方法

    Application.Idle()方法表示:当应用程序处于空闲状态时执行相应代码. 示例程序 1.界面设计:一个简单的Lable控件 2.代码 using System; using System. ...

  4. TopK的一个简单实现

    转自:http://rangerwolf.iteye.com/blog/2119096 题外话: <Hadoop in Action> 是一本非常不错的交Hadoop的入门书,而且建议看英 ...

  5. cmd命令行编码设置

    cmd窗口情况下:windows下cmd默认的编码是GBK 想在windows下查看sqlite的utf-8中文需要先 执行chcp 65001把当前页换为utf-8编码 chcp 命令: chcp ...

  6. pyqt的多Button的点击事件的槽函数的区分发送signal的按钮。

    关键函数:QPushButton的setObjectName()/objectName() 个人注解:按功能或者区域,将按钮的点击事件绑定的不同的槽函数上. from PyQt5.QtWidgets ...

  7. office2003 下载地址 及密码

    http://www.downxia.com/downinfo/63.html microsoft office 2003 密钥 GWH28-DGCMP-P6RC4-6J4MT-3HFDY Micro ...

  8. MVC+LINQToSQL的Repository模式之(一)数据工厂 DataContext绑定线程

    namespace Data{    /// <summary>    /// 数据库建立工厂    /// Created By : 张占岭    /// Created Date:20 ...

  9. Unity 移动端的复制这么写

    游戏上线很久了,有些玩家慢慢就流失了,为了让刚流失的玩家再度回归所以做了召回功能!如果一个200级的玩家10天没上线且成功召回的,就会给予召回玩家丰厚的奖励! Q:那如何召回这个流失的玩家呢? A:召 ...

  10. Java精选笔记_集合【Set(集合)接口】

    Set(集合)接口 简介 同样继承自Collection接口,它与Collection接口中的方法基本一致,并没有对Collection接口进行功能上的扩充,只是比Collection接口更加严格了. ...