体面:

我的代码:
#include<bits/stdc++.h>
using namespace std;
int n,maxa=-1;
map<int,int>t,p,p2;
struct node
{
int a,b;
void input()
{
cin>>a>>b;
if(a>b)swap(a,b);
}
bool operator < (node &o)
{
if(a!=o.a)return a<o.a;
return b<o.b;
}
}k[200005];
void dg(int now)
{
cout<<now<<" "<<t[now]<<endl;
if(t[now]==1)return;
t[now]=1;
maxa=max(maxa,now);
for(int i=p[now];i<=p[now]+p2[now];i++)
{
cout<<k[i].b<<endl;
dg(k[i].b);
}
// t[now]=0;
return;
}
int main()
{
cin>>n;
for(int i=1;i<=n;i++)k[i].input();
sort(k+1,k+n+1);
for(int i=1;i<=n;i++)
{
if(p[k[i].a]!=0)p[k[i].a]=i;
p2[k[i].a]++;
}
if(p2[1]==0)cout<<1;
else
{
// cout<<p2[1]<<endl;
for(int i=p[1];i<=p[1]+p2[1];i++)
{
dg(k[i].b);
}
cout<<maxa;
}
return 0;
}