# 杭电多校第二场 1003 HDU-6311 Cover（欧拉回路）

102 篇文章 0 订阅
1 篇文章 0 订阅

Cover
Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 388    Accepted Submission(s): 56
Special Judge

Problem Description
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.

Input
There 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

Output
For 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

4->2->1->3->2

1->4->3

#include <bits/stdc++.h>
#define fi first
#define se second
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lowbit(x) x&-x
#define MP make_pair
#define pb push_back
#define debug(x) cout<<x<<"= "<<x<<endl
#define FIN freopen("in.txt","r",stdin)
#define clr(a) memset(a,0,sizeof(a))
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int>pii;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
const ll infll=0x3f3f3f3f3f3f3f3f;
const int MX=1e5+7;

int n,m;
struct edge{
int v,nxt;
}E[MX<<2];
bool vis[MX],vis2[MX<<2];
int num;
vector<int>v,ans[MX];
void init(){
num=0;tot=1;
v.clear();
}
}
void dfs(int u){
vis[u]=1;
if(du[u]&1) v.pb(u);
int v=E[i].v;
if(vis[v]) continue;
dfs(v);
}
}
void dfs2(int u){
if(!vis2[i]){
vis2[i]=vis2[i^1]=1;
int v=E[i].v;
dfs2(v);
if(i>2*m+1) num++;
else{
int cnt=i&1?(i/2):(-i/2);
ans[num].pb(cnt);
}
}
}
}
void solve(){
for(int i=1;i<=n;i++){
if(!vis[i] && du[i]){
dfs(i);
for(int j=2;j<v.size();j+=2){
}
num++;
if(v.size()) dfs2(v[0]);
else dfs2(i);
v.clear();
}
}
printf("%d\n",num);
for(int i=1;i<=num;i++){
int sz=ans[i].size();
printf("%d ",sz);
for(int j=0;j<sz;j++)
printf("%d%c",ans[i][j],j==sz-1?'\n':' ');
ans[i].clear();
}
}

int main(){
while(~scanf("%d%d",&n,&m)){
init();
for(int i=1;i<=m;i++){
int u,v;scanf("%d%d",&u,&v);
du[u]++;du[v]++;
}
solve();
}
return 0;
}

• 0
点赞
• 0
收藏
觉得还不错? 一键收藏
• 0
评论
05-04 232
08-02 414
11-30 461
07-23 637
07-26 180
02-25 4168

### “相关推荐”对你有帮助么？

• 非常没帮助
• 没帮助
• 一般
• 有帮助
• 非常有帮助

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、付费专栏及课程。