提交时间:2022-06-18 20:03:08

运行 ID: 41848

#include<iostream> short n,m,from,to,a[100][100],d[100],s,way[101],cw; void dfs(short p){ way[cw++]=p; for(short i=0;i<n;i++){ if(a[p][i]){ a[p][i]=0; a[i][p]=0; dfs(i); } } } int main(){ scanf("%hd %hd",&n,&m); for(short i=0;i<m;i++){ scanf("%hd %hd",&from,&to); a[from-1][to-1]=1; a[to-1][from-1]=1; d[from-1]++; d[to-1]++; } for(short i=1;i<n;i++){ if(d[i]%2){ s=i; break; } } dfs(s); for(short i=0;i<cw;i++) printf("%hd ",way[i]+1); return 0; }