https://www.luogu.com.cn/record/157074874
#include<bits/stdc++.h>
#define N 3000
#define reg register
using namespace std;
int a[N][N];
stack<int>stk;
int s[N];
int n;
int b,c;
int t;
void dfs(int y)
{
for(reg int j=1;j<=n;j++)
{
if(a[y][j]==1)
{
a[y][j]=a[j][y]=0;
dfs(j);
}
}
stk.push(y);
}
int maxx=0;
signed main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>n;
for(reg int i=1;i<=n;i++)
{
cin>>b>>c;
maxx=max(maxx,max(b,c));
a[b][c]=a[c][b]=1;
s[b]++;
s[c]++;
}
int flag=1;
for(reg int i=1;i<=N;i++)
{
if(s[i]%2==1)
{
flag=i;
break;
}
}
dfs(flag);
while(!stk.empty())
{
cout<<stk.top()<<"\n";
stk.pop();
}
return 0;
}