题意
给你一个有向图或无向图,要求输出其中一条欧拉回路。
n≤100000 n ≤ 100000
分析
圈套圈算法求欧拉回路的模版题。
这个算法大概是,从某个点开始走,然后用一个栈存放所有走过的点。当走到死胡同时就退栈,直到退到某个点仍然存在出边,然后继续沿着出边走下去。
这可以看成是先找到一个环,然后再找到另一个环,接着把这两个环拼在一起,就形成了一个更大的环。不停的操作下去,就可以得到极大环也就是欧拉回路了。
代码
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
const int N=100005;
int ty;
struct Task1
{
int n,m,cnt,last[N],deg[N],f[N],stack[N*2],num[N*2],ans[N*2],tot;
struct edge{
int to,next,id;bool use;}e[N*4];
void addedge(int u,int v)
{
e[++cnt].to=v;e[cnt].next=last[u];last[u]=cnt;
e[++cnt].to=u;e