欧拉图bz
给一个无向图,输出欧拉图顺序
//答案存在了ans数组,abs[1-t] int sta[1000010],ans[1000010],vis[1000010]; int n,m,top,t; void euler() { sta[++top] = 1; while(top > 0) { int x = sta[top], i = head[x]; while(i && vis[i]) i = Next[i]; //找到一条尚未访问过的边 if(i) { sta[++top] = ver[i]; vis[i] = vis[i ^ 1] = true; head[x] = nextt[i]; }else{ //x连接的所有边都已经访问过了,回溯,级在答案栈中 top--; ans[++t] = x; } } } // main scanf("%d%d", &n, &m); tot = 1; int x, y; for(int i = 0; i < m; ++i) { scanf("%d%d", &x, &y); add(x, y); add(y, x); } euler(); for(int i = t; i; --i) { printf("%d\n", ans[i]); }