求大佬指点
by ynzzr @ 2018-10-20 11:56:48
代码如下
```cpp
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>P;
const int M=100005;
int n,m;
int head[M],asdf;
bool mark[M*10],vis[M];
int du[M],que[M*20],len;
vector<P>ans;
struct edge {
int to,nxt,id;
} G[M*20];
void add_edge(int a,int b,int c) {
G[++asdf].to=b;
G[asdf].nxt=head[a];
G[asdf].id=c;
head[a]=asdf;
}
void dfs(int x) {
vis[x]=1;
for(int &i=head[x]; i; i=G[i].nxt) {
if(mark[G[i].id])continue;
int y=G[i].to;
mark[G[i].id]=1;
dfs(y);
ans.push_back(P(x,y));
}
}
int stk[M],top;
int cnt[M],po[M*100];
int main() {
int a,b,x,y;
scanf("%d %d",&n,&m);
for(int i=1; i<=m; i++) {
scanf("%d %d %d %d",&a,&b,&x,&y);
if(x==y)continue;
add_edge(a,b,i);
add_edge(b,a,i);
du[a]++,du[b]++;
que[++len]=a,que[++len]=b;
}
sort(que+1,que+1+len);
len=unique(que+1,que+1+len)-que-1;
bool flag=1;
for(int i=1; i<=len; i++) {
if(du[que[i]]&1)flag=0;
}
if(!flag)printf("NIE\n");
else {
for(int i=1; i<=len; i++) {
if(!vis[que[i]]) {
dfs(que[i]);
}
}
int sum=0;
top=0;
memset(cnt,0,sizeof(cnt));
for(int i=ans.size()-1; i>=0; i--) {
x=ans[i].first;
if(!cnt[x])stk[++top]=x,cnt[x]++;
y=ans[i].second;
cnt[y]++;
if(cnt[y]==2) {
cnt[y]--;
sum++;
po[sum]=1;
while(stk[top]!=y)cnt[stk[top--]]--,po[sum]++;
} else stk[++top]=y;
}
printf("%d\n",sum);
top=0;
memset(cnt,0,sizeof(cnt));
sum=0;
for(int i=ans.size()-1; i>=0; i--) {
x=ans[i].first;
if(!cnt[x])stk[++top]=x,cnt[x]++;
y=ans[i].second;
cnt[y]++;
if(cnt[y]==2) {
cnt[y]--;
sum++;
printf("%d ",po[sum]);
printf("%d ",y);
while(stk[top]!=y) {
printf("%d ",stk[top]);
cnt[stk[top--]]--;
}
printf("%d\n",y);
} else stk[++top]=y;
}
}
return 0;
}
```
by ynzzr @ 2018-10-20 11:58:56
哪里有错?
by ynzzr @ 2018-10-20 11:59:16
大佬求帮助
by ynzzr @ 2018-10-20 11:59:27
@[zzr太巨了](/space/show?uid=122943) $CPU$时间超限了
by Sya_Resory @ 2018-10-20 12:25:55
@[Dream_Chaser](/space/show?uid=114082) 你的意思是换一台CPU高级的电脑就可以过了?
by ynzzr @ 2018-10-20 12:46:29
@[zzr太巨了](/space/show?uid=122943) 我看的UKE注释……
by Sya_Resory @ 2018-10-20 12:48:38