#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;

int a[500010][2],dfn[500010],rdfn[500010];
int st[500010][15];

int maxx[2000010];

void build(int x,int l,int r){
    if(l==r){
        maxx[x]=dfn[l];
        return;
    }
    int m=(l+r)/2;
    build(2*x,l,m);
    build(2*x+1,m+1,r);
    maxx[x]=max(maxx[2*x],maxx[2*x+1]);
}

int q(int x,int L,int R,int l,int r){
    if()
    if(l==L&&r==R){
        return maxx[x];
    }
    int m=(l+r)/2;
    return max(q(2*x,L,m,l,m),q(2*x+1,m+1,r));
    
}

int main(){
    freopen("query.in","r",stdin);
    freopen("query.out","w",stdout);
    int n;
    cin>>n;
    for(int i=1;i<n;i++){
        int u,v;
        cin>>u>>v;
        if(a[u][0]){
            a[u][1]=v;
        }
        else{
            a[u][0]=v;
        }
        if(a[v][0]){
            a[v][1]=u;
        }
        else{
            a[v][0]=u;
        }
    }
    int p=1,lst=0;
    dfn[1]=1;rdfn[1]=1;
    for(int i=2;i<=n;i++){
        if(a[p][1]==lst){
            lst=p;
            p=a[p][2];
        }
        else{
            lst=p;
            p=a[p][1];
        }
        dfn[p]=i;rdfn[i]=p;
    }
    return 0;
}