HDU - 6311:Cover(欧拉回路,最少的一笔画覆盖无向图)
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.
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(欧拉回路,最少的一笔画覆盖无向图)的更多相关文章
- HDU 6311 Cover (无向图最小路径覆盖)
HDU 6311 Cover (无向图最小路径覆盖) Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/ ...
- HDU - 6311 Cover(无向图的最少路径边覆盖 欧拉路径)
题意 给个无向图,无重边和自环,问最少需要多少路径把边覆盖了.并输出相应路径 分析 首先联通块之间是独立的,对于一个联通块内,最少路径覆盖就是 max(1,度数为奇数点的个数/2).然后就是求欧拉路 ...
- HDU - 6311 Cover (欧拉路径)
题意:有最少用多少条边不重复的路径可以覆盖一个张无向图. 分析:对于一个连通块(单个点除外),如果奇度数点个数为 k,那么至少需要max{k/2,1} 条路径.将奇度数的点两两相连边(虚边),然后先 ...
- hdu 5386 Cover (暴力)
hdu 5386 Cover Description You have an matrix.Every grid has a color.Now there are two types of oper ...
- HDU 6311 最少路径覆盖边集 欧拉路径
Cover Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- hdu 6311 欧拉回路
题意:求一个图(不一定联通)最小额外连接几条边,使得可以一笔画出来 大致做法 1.找出联通块 2.统计每一个连通块里面度数为奇数的点的个数, 有一个性质 一个图能够用一笔画出来,奇数点的个数不超过2个 ...
- hdu 1150 Machine Schedule 最少点覆盖转化为最大匹配
Machine Schedule Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...
- hdu 1150 Machine Schedule 最少点覆盖
Machine Schedule Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...
- HDOJ 1878 欧拉回路 nyoj 42一笔画问题
#include<cstdio> #include<cstring> ]; int find(int x) { if(visited[x]!=x) return find(vi ...
随机推荐
- Spring AOP 切面编程记录日志和接口执行时间
最近客户现在提出系统访问非常慢,需要优化提升访问速度,在排查了nginx.tomcat内存和服务器负载之后,判断是数据库查询速度慢,进一步排查发现是因为部分视图和表查询特别慢导致了整个系统的响应时间特 ...
- Python requests快速上手
Python requests快速上手 这里参考官方文档,在ide中写了一遍,加深一下印象,定义的函数只是为了方便区分不同的请求方式 #-*-coding:utf-8-*- # Time:2017/1 ...
- linux下ssh公钥验证的设置和远程登录
1.第一步 在自己本机,通过工具生成一对公私钥对,对应id_rsa/id_rsa.pub 2.第二步 修改服务器配置 1)复制id_rsa.pub公钥内容 将文件内容追加到~/.ssh/ ...
- 4-6 select_tag和select的区别和理解。javascript_tag
via: :all是什么意思?主要用于约束http动作. <%= select_tag "set_locale", options_for_select(LANGUAGES, ...
- Sergey's problem CodeForces - 1019C (图论,构造,神题)
链接 大意: 给定有向图, 求选择一个点集$S$, 使得$S$任意两点不相连, 且对于不属于$S$的任意点$x$, 均存在$S$中的点$y$, 使得$d(x,y)<=2$, $d(x,y)$为从 ...
- ASP.NET的路由系统
一.URL与物理文件的分离 1.URL与物理文件的分离 对于一个 ASP.NET Web Form应用来说,任何一个请求都对应着某个具体的物理文件.部署在Web服务器上的物理文件可以是静态的(比如图片 ...
- JAVA 中CLOB与Clob有区别
在JAVA中CLOB与Clob是有区别的类型. (oracle.jdbc.internal.OracleCallableStatement)OracleCallableStatement能接收CLOB ...
- ES 分布式搜索
ES整个查询过程是scatter/gather的过程,具体如下: 图见 https://blog.csdn.net/thomas0yang/article/details/78572596?utm_s ...
- Python学习之路day3-集合
一.概述 集合(set)是一种无序且不重复的序列. 无序不重复的特点决定它存在以下的应用场景: 去重处理 关系测试 差集.并集.交集等,下文详述. 二.创建集合 创建集合的方法与创建字典类似,但没有键 ...
- 简话Angular 01 初识Angular 数据绑定
1. Angular有哪些突出优点 1) MVC 基于Html-Javascript 2) 依赖注入 3) 数据双向绑定,响应式页面设计 4) 模块化,自定义指令 2. 简话数据绑定 1) 代码: & ...