hdu多校2C
题意:找多条路径覆盖所有的边,求最小路径数,要求输出路径
题解:新建一个点n+1,所有奇点向它连边,然后跑欧拉回路,最后把新加的边删去,一段连续的边就是一条路径
= =但是由于太久没写欧拉回路以及之前的板子有点问题,导致比赛时没做出来
还有一个坑点是,明明题目里说了没有重边,我规定不能访问父亲居然就wa了!!!!
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define vi vector<int>
#define mod 1000000007
#define ld long double
#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
#define cd complex<double>
#define ull unsigned long long
#define base 1000000000000000000
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
#define fio ios::sync_with_stdio(false);cin.tie(0)
inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline ll qp(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
using namespace std;
const double eps=1e-8;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int N=200000+10,maxn=400000+10,inf=0x3f3f3f3f;
struct edge{
int to,Next,id;
}e[maxn];
int cur[N];
int cnt,head[N],deg[N];
vi s[N];
int res,n,m,sum;
bool ban[maxn];
inline void init()
{
cnt=res=sum=0;
for(int i = 1; i <= n + 1; i++) {
head[i] = -1;
deg[i] = 0;
}
}
inline void add(int u,int v,int id)
{
e[cnt].to=v;
e[cnt].Next=head[u];
e[cnt].id=id;
ban[cnt] = false;
head[u]=cnt++;
e[cnt].to=u;
e[cnt].Next=head[v];
e[cnt].id=id;
ban[cnt] = false;
head[v]=cnt++;
}
void dfs(int u,int f)
{
// cout << u << " " << f << endl;
// for(int i=head[u];~i;i=e[i].Next)
while(head[u] != -1)
{
int i = head[u];
int x=e[i].to;
head[u] = e[i].Next;
if(!ban[e[i].id])
{
ban[e[i].id]=1;
dfs(x,u);
if(u!=n+1)
{
if(x!=n+1)
{
s[res].pb(i&1?-e[i].id:e[i].id);
}
else
{
if((int)s[res].size()!=0)res++;
}
}
}
}
}
int main()
{
int a, b;
while(~scanf("%d%d",&n, &m))
{
init();
for(int i=1;i<=m;i++)
{
scanf("%d%d", &a, &b);
add(a,b,i);
deg[a]++,deg[b]++;
}
int te=m;
for(int i=1;i<=n;i++)
if(deg[i]&1)
add(i,n+1,++te);
dfs(n+1,-1);
if((int)s[res].size()!=0)res++;
for(int i=1,j;i<=n;i++)
while((j=head[i])!=-1){
head[i] = e[j].Next;
if(!ban[e[j].id])
{
dfs(i,-1);
if(s[res].size()!=0)res++;
}
}
printf("%d\n",res);
for(int i=0;i<res;i++)
{
printf("%d",s[i].size());
for(int j=s[i].size() - 1;j >= 0;--j)
printf(" %d",s[i][j]);
puts("");
s[i].clear();
}
// for(int i = 1; i <= n; i++) printf("%d ", head[i]);
}
return 0;
}
/********************
6 6
1 2
2 3
3 4
2 5
3 5
2 6
6 6
1 2
2 3
1 3
4 5
5 6
4 6
31 36
12 28
12 27
27 28
15 26
15 25
25 26
17 23
17 24
23 24
20 21
20 22
21 22
29 30
30 31
29 31
1 2
2 3
3 4
1 4
4 5
4 6
5 7
6 7
7 8
8 9
9 10
10 11
11 12
10 14
14 15
10 13
13 16
16 17
13 18
18 19
19 20
8 7
1 2
2 3
3 4
4 8
5 6
6 7
7 4
********************/
hdu多校2C的更多相关文章
- 2018 HDU多校第四场赛后补题
2018 HDU多校第四场赛后补题 自己学校出的毒瘤场..吃枣药丸 hdu中的题号是6332 - 6343. K. Expression in Memories 题意: 判断一个简化版的算术表达式是否 ...
- 2018 HDU多校第三场赛后补题
2018 HDU多校第三场赛后补题 从易到难来写吧,其中题意有些直接摘了Claris的,数据范围是就不标了. 如果需要可以去hdu题库里找.题号是6319 - 6331. L. Visual Cube ...
- 2015 HDU 多校联赛 5363 Key Set
2015 HDU 多校联赛 5363 Key Set 题目: http://acm.hdu.edu.cn/showproblem.php? pid=5363 依据前面给出的样例,得出求解公式 fn = ...
- 2015 HDU 多校联赛 5317 RGCDQ 筛法求解
2015 HDU 多校联赛 5317 RGCDQ 筛法求解 题目 http://acm.hdu.edu.cn/showproblem.php? pid=5317 本题的数据量非常大,測试样例多.数据 ...
- [HDU多校]Ridiculous Netizens
[HDU多校]Ridiculous Netizens 点分治 分成两个部分:对某一点P,连通块经过P或不经过P. 经过P采用树形依赖背包 不经过P的部分递归计算 树型依赖背包 v点必须由其父亲u点转移 ...
- 【杂题总汇】HDU多校赛第十场 Videos
[HDU2018多校赛第十场]Videos 最后一场比赛也结束了…… +HDU传送门+ ◇ 题目 <简要翻译> 有n个人以及m部电影,每个人都有一个快乐值.每场电影都有它的开始.结束时间和 ...
- hdu多校1002 Balanced Sequence
Balanced Sequence Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s) ...
- HDU多校(Distinct Values)
Problem Description Chiaki has an array of n positive integers. You are told some facts about the ar ...
- hdu多校6
这个场要恶心死我了.. 1001 积分题,不要四舍五入 //#pragma comment(linker, "/stack:200000000") //#pragma GCC op ...
随机推荐
- 2016NOI冬令营day0
上午写了一道题. 中午收拾好东西后兴高采烈地坐老司机开的出租车来到了美丽的南山中学!!!:) 志愿者太多了,弄得我们有点不好意思......:) 来到寝室,看到了传闻中的被子&空(kong4) ...
- [转载]ASP.NET-----Repeater数据控件的用法总结
一.Repeater控件的用法流程及实例: 1.首先建立一个网站,新建一个网页index.aspx. 2.添加或者建立APP_Data数据文件,然后将用到的数据库文件放到APP_Data文件夹中. 3 ...
- live555 编译
项目里面需要简单的rtsp服务器来实现视频预览等功能: rtsp本来不是太复杂的东西,github上有很多功能都比较完善的项目可以随便拿来用,但是测试过程中发现live555还是有性能上的一些差异: ...
- SQL学习之SQL注入学习总结
所谓SQL注入,就是通过把SQL命令插入到Web表单提交或输入域名或页面请求的查询字符串,最终达到欺骗服务器执行恶意的SQL命令. 测试数据库 我们本文就以如下数据库作为测试数据库,完成我们的注入分析 ...
- mybatis 3的TypeHandler深入解析(及null值的处理)
最近,在测试迁移公司的交易客户端连接到自主研发的中间件时,调用DAO层时,发现有些参数并没有传递,而在mapper里面是通过parameterMap传递的,因为有些参数为null,这就导致了参数传递到 ...
- Android JSON 解析关键代码
Android Json 解析其实还是蛮重要的知识点,为什么这么说呢,因为安卓通信大部分的协议都是使用 json 的方式传输,我知道以前大部分是使用的 xml ,但是时代在发展社会在进步,json 成 ...
- The DELETE statement conflicted with the REFERENCE constraint
Page是主表,主键是pageid:UserGroupPage表中的PageID字段是Page表里的数据. https://www.codeproject.com/Questions/677277/I ...
- BZOJ1632: [Usaco2007 Feb]Lilypad Pond SPFA+最短路计数
Description 为了让奶牛们娱乐和锻炼,农夫约翰建造了一个美丽的池塘.这个长方形的池子被分成了M行N列个方格(1≤M,N≤30).一些格子是坚固得令人惊讶的莲花,还有一些格子是岩石,其余的只是 ...
- [bzoj 1616][Usaco2008 Mar]Cow Travelling游荡的奶牛
题目描述 奶牛们在被划分成N行M列(2 <= N <= 100; 2 <= M <= 100)的草地上游走,试图找到整块草地中最美味的牧草.Farmer John在某个时刻看见 ...
- UVa 1632 阿里巴巴(区间DP)
https://vjudge.net/problem/UVA-1632 题意: 直线上有n个点,其中第i个点的坐标是xi,且它会在di秒之后消失.Alibaba可以从任意位置出发,求访问完所有点的最短 ...