如果一个无向图存在一笔画,则一笔画的路径叫做欧拉路,如果最后又回到起点,那这个路径叫做欧拉回路。
#include<bits/stdc++.h>
using namespace std;
#define N 510
int g[N][N],d[N],c[N],n,m,reckon,oddity_point,lt;
void dfs(int i)
{for(int j=1;j<=n;j++){if(g[i][j]==1){g[i][j]=0;g[j][i]=0;dfs(j);}}c[++reckon]=i;return;
}
int main()
{cin>>n>>m;int x,y;memset(g,0,sizeof(g));for(int i=1;i<=m;i++){cin>>x>>y;g[x][y]=1;g[y][x]=1;d[x]++;d[y]++;}int z=1;for(int i=1;i<=n;i++){if(d[i]%2==1){z=i;oddity_point++;}if(d[i]==0){lt++;}}dfs(z);if(oddity_point!=2&&oddity_point!=0){cout<<"NO";return 0;}if(lt!=0){cout<<"NO";return 0;}for(int i=1;i<=reckon;i++){cout<<c[i]<<" ";}return 0;
}