违规用户名U56916 @ 2018-01-26 17:59:35
#include<bits/stdc++.h>
using namespace std;
struct bi{
int x,y;
}a[1024];
int n,d[1025],pd=0,b[501],qi=501,f[501][501],maxx,minn=501;
void sc(){
pd=1;
for(int i=0;i<=n;i++){
cout<<d[i]<<endl;
}
}
int dfs(int kai,int wei){
for(int i=minn;i<=maxx;i++){
if(f[kai][i]>0){
f[kai][i]--;
f[i][kai]--;
d[wei]=i;
dfs(i,wei+1);
if(wei==n) sc();
}
if(pd==1) return 0;
}
}
int main(){
cin>>n;
for(int i=0;i<n;i++){
cin>>a[i].x>>a[i].y;
b[a[i].x]++;
b[a[i].y]++;
f[a[i].x][a[i].y]++;
f[a[i].y][a[i].x]++;
maxx=max(maxx,max(a[i].x,a[i].y));
minn=min(minn,min(a[i].x,a[i].y));
}
for(int i=minn;i<=maxx;i++){
if(b[i]%2==1) {qi=i;break;}
}
if(qi==501) qi=minn;
d[0]=qi;
dfs(qi,1);
return 0;
}
by 大不美列坚 @ 2021-05-03 17:25:25
同问 QWQ