#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;
int edge[10005][10005];
int n,m;
int stk[10005],h;
inline void stkinput(int n){
stk[++h]=n;
return;
}
inline void stkoutput(){
stk[h]=stk[0];
h--;
return;
}
inline void dfs(int t){
stkinput(t);
while(h>0){
int head=stk[h];
printf("%d\n",head);
bool flag1=0;
for(int i=1;i<=n;i++){
if(edge[head][i]>=1){
flag1=1;
while(edge[head][i]>1){
edge[head][i]--;
edge[i][head]--;
printf("%d\n%d\n",i,head);
}
edge[head][i]--;
edge[i][head]--;
stkinput(i);
break;
}
}
if(!flag1) stkoutput();
}
return;
}
int main(){
scanf("%d%d",&n,&m);
for(int i=0;i<m;i++){
int fr,t;
scanf("%d%d",&fr,&t);
edge[fr][t]++;
edge[t][fr]++;
}
dfs(1);
return 0;
}
提交记录 第九个测试点WA,其余AC