The Wall has down and the King in the north has to send his soldiers to sentinel.
The North can be regard as a undirected graph (not necessary to be
connected), one soldier can cover one path. Today there's no so many
people still breathing in the north, so the King wants to minimize the
number of soldiers he sent to cover each edge exactly once. As a master
of his, you should tell him how to arrange soldiers.
InputThere might be multiple test cases, no more than 20. You need to read till the end of input.

In the first line, two integers n and m, representing the number of nodes and edges in the graph.

In the following m lines, each contain two integers, representing two ends of an edge.

There are no parallel edges or self loops.

1≤n,m≤100000
OutputFor each test case, the first line contains number of needed routes, p.

For the following p lines, an integer x in the beginning, followed
by x integers, representing the list of used edges. Every integer should
be a positive or negative integer. Its absolute value represents the
number of chosen edge (1~n). If it's positive, it shows that this edge
should be passed as the direction as the input, otherwise this edge
should be passed in the direction different from the input. Edges should
be in correct order.Sample Input

3 3
1 2
1 3
2 3

Sample Output

1
3 1 3 -2

思路:把奇点配对,然后求欧拉回路。

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int maxn=;
int Laxt[maxn],Next[maxn<<],To[maxn<<],cnt,num;
int x[maxn],y[maxn],ind[maxn]; bool used[maxn],vis[maxn<<];
vector<int>G[maxn]; int tot,M;
void add(int u,int v)
{
Next[++cnt]=Laxt[u]; Laxt[u]=cnt; To[cnt]=v; vis[cnt]=;
}
void dfs(int u,int f)
{
used[u]=;
for(int &i=Laxt[u];i;i=Next[i]){
if(!vis[i]){
vis[i]=vis[i^]=;
dfs(To[i],i);
}
}
if(!f) return ;
if(f<=(M<<|)) G[tot].push_back(f&?(f>>):-(f>>));
else tot++;
}
int main()
{
int N;
while(~scanf("%d%d",&N,&M)){
rep(i,,M) scanf("%d%d",&x[i],&y[i]);
cnt=; tot=;
rep(i,,N) Laxt[i]=used[i]=ind[i]=;
rep(i,,M) {
add(x[i],y[i]); add(y[i],x[i]);
ind[x[i]]++; ind[y[i]]++;
}
int x=;
rep(i,,N) {
if(ind[i]&){
if(x) add(x,i), add(i,x),x=;
else x=i;
}
}
rep(i,,N) if(!used[i]&&(ind[i]&)){
tot++; dfs(i,); tot--;
}
rep(i,,N) if(!used[i]&&ind[i]) {
tot++; dfs(i,);
}
printf("%d\n",tot);
rep(i,,tot) {
printf("%d",G[i].size()); int L=G[i].size();
rep(j,,L-) printf(" %d",G[i][j]); puts("");
}
rep(i,,tot) G[i].clear();
}
return ;
}

HDU - 6311:Cover(欧拉回路,最少的一笔画覆盖无向图)的更多相关文章

  1. HDU 6311 Cover (无向图最小路径覆盖)

    HDU 6311 Cover (无向图最小路径覆盖) Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/ ...

  2. HDU - 6311 Cover(无向图的最少路径边覆盖 欧拉路径)

    题意 给个无向图,无重边和自环,问最少需要多少路径把边覆盖了.并输出相应路径 分析 首先联通块之间是独立的,对于一个联通块内,最少路径覆盖就是  max(1,度数为奇数点的个数/2).然后就是求欧拉路 ...

  3. HDU - 6311 Cover (欧拉路径)

    题意:有最少用多少条边不重复的路径可以覆盖一个张无向图. 分析:对于一个连通块(单个点除外),如果奇度数点个数为 k,那么至少需要max{k/2,1}  条路径.将奇度数的点两两相连边(虚边),然后先 ...

  4. hdu 5386 Cover (暴力)

    hdu 5386 Cover Description You have an matrix.Every grid has a color.Now there are two types of oper ...

  5. HDU 6311 最少路径覆盖边集 欧拉路径

    Cover Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  6. hdu 6311 欧拉回路

    题意:求一个图(不一定联通)最小额外连接几条边,使得可以一笔画出来 大致做法 1.找出联通块 2.统计每一个连通块里面度数为奇数的点的个数, 有一个性质 一个图能够用一笔画出来,奇数点的个数不超过2个 ...

  7. hdu 1150 Machine Schedule 最少点覆盖转化为最大匹配

    Machine Schedule Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...

  8. hdu 1150 Machine Schedule 最少点覆盖

    Machine Schedule Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...

  9. HDOJ 1878 欧拉回路 nyoj 42一笔画问题

    #include<cstdio> #include<cstring> ]; int find(int x) { if(visited[x]!=x) return find(vi ...

随机推荐

  1. Qt5.3.2(VS2010)_调试_查看变量值

    1.菜单栏 -->控件(W) --> 视图 2.在"Debug"状态下,选择一个变量(或者 按住左键 选择变量及其属性/方法)--> 右键 --> 添加表达 ...

  2. Qt5_自定义处理Windows消息函数

    ZC:(1).“#include <QAbstractNativeEventFilter>”,(2).貌似 返回True(意思是 处理过了) 返回False(意思是还需要继续处理) 1.参 ...

  3. Codeforces 918D - MADMAX

    918D - MADMAX 思路: dp+记忆化搜索 状态:dp[i][j][w]表示先手在i节点,后手在j节点,这一轮的字母为w的结果,如果为true,则表示先手必赢,否则后手必赢. 状态转移:如果 ...

  4. ASCII 对照表

    ASCII(American Standard Code for Information Interchange,美国信息互换标准代码,ASCⅡ)是基于拉丁字母的一套电脑编码系统.它主要用于显示现代英 ...

  5. 雷林鹏分享:C# 正则表达式

    C# 正则表达式 正则表达式 是一种匹配输入文本的模式..Net 框架提供了允许这种匹配的正则表达式引擎.模式由一个或多个字符.运算符和结构组成. 定义正则表达式 下面列出了用于定义正则表达式的各种类 ...

  6. WPF编程学习 —— 样式

     本文目录 1.引言 2.怎样使用样式? 3.内联样式 4.已命名样式 5.元素类型样式 6.编程控制样式 7.触发器 1.引言 样式(Style),主要是用来让元素或内容呈现一定外观的属性.WPF中 ...

  7. codeforces 547c// Mike and Foam// Codeforces Round #305(Div. 1)

    题意:给出数组arr和一个空数组dst.从arr中取出一个元素到dst为一次操作.问每次操作后dst数组中gcd等于1的组合数.由于数据都小于10^6,先将10^6以下的数分解质因数.具体来说从2开始 ...

  8. javaScript 的 map() reduce() foreach() filter()

    map(映射), reduce(规约), forEach(遍历), filter(过滤),它们都是高阶函数,都是以传入不同的函数来以不同的方式操作数组元.ie都不支持 一.map方法 *概述 map( ...

  9. hdu-4289 最大流Dinic模板题

    拆点,套模板. 详情见代码. // // main.cpp // hdu_4289 // // Created by Luke on 16/8/29. // Copyright © 2016年 Luk ...

  10. mysql语句查询时间检测

    explain的使用 1.首先我们是要登入你的mysql的,然后选择数据库输入:use 你要选择的库名 2执行语句 eg:  explain SELECT * FROM wish_orders1412 ...