P2731 双向OLa
C++//god_std 2025.6.9 21:14
//P2731 双向OLa
#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read()
{
int x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9')
{
if(ch=='-')f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9')
{
x=x*10+(int)(ch-'0');
ch=getchar();
}
return f*x;
}
int n=read();
int e[1026][1026];
int d[100001];
stack<int> st;
void dfs(int u)
{
for(int v=1; v<=500; v++)
{
if(e[u][v]>0)
{
e[u][v]--;
e[v][u]--;
dfs(v);
// break;
}
}
st.push(u);
}
signed main()
{
int s=1;
for(int i=1; i<=n; i++)
{
int u=read();
int v=read();
e[u][v]++;
e[v][u]++;
d[u]++;
d[v]++;
}
for(int i=500; i>=1; i--)
{
if(d[i]%2==1)
{
s=i;
}
}
if(s==1)
{
for(int i=1; i<=500; i++)
{
if(d[i]!=0)
{
s=i;
break;
}
}
}
dfs(s);
while(!st.empty())
{
cout<<st.top()<<endl;
st.pop();
}
return 0;
}