找规律
#include<bits/stdc++.h>
using namespace std;
using LL = long long;
const int M = 1000006;
int n;
int st;
int cnt[M];
unordered_map<int, int> v;
queue<int> q;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n;
for(int i = 0; i < n; i ++ )
{
int a, b;
cin >> a >> b;
v[a] = b;
cnt[a] ++;
cnt[b] ++;
}
for(int i = 1; i < M; i ++ )
if(cnt[i] == 1 && v.count(i))
st = i;
cout << st << " " << v[0] << " ";//第一个和第二个元素
q.push(st);
q.push(v[0]);
while(q.size())
{
int t = q.front();
q.pop();
if(v.count(t) && v[t] != 0)
cout << v[t] << " ";
if(v[t] != 0) q.push(v[t]);
}
return 0;
}