Problem:
Score : 900 points

Problem Statement

Takahashi has an ability to generate a tree using a permutation (p_1,p_2,...,p_n) of (1,2,...,n), in the following process:

First, prepare Vertex 1, Vertex 2, ..., Vertex N.
For each i=1,2,...,n, perform the following operation:

If p_i = 1, do nothing.

If p_i \neq 1, let j' be the largest j such that p_j < p_i. Span an edge between Vertex i and Vertex j'.

Takahashi is trying to make his favorite tree with this ability.
His favorite tree has n vertices from Vertex 1 through Vertex n, and its i-th edge connects Vertex v_i and w_i.
Determine if he can make a tree isomorphic to his favorite tree by using a proper permutation.
If he can do so, find the lexicographically smallest such permutation.

Notes

For the definition of isomorphism of trees, see wikipedia. Intuitively, two trees are isomorphic when they are the "same" if we disregard the indices of their vertices.

Constraints

2 \leq n \leq 10^5

1 \leq v_i, w_i \leq n

The given graph is a tree.

Input

Input is given from Standard Input in the following format:

n
v_1 w_1
v_2 w_2
:
v_{n-1} w_{n-1}

Output

If there is no permutation that can generate a tree isomorphic to Takahashi's favorite tree, print -1.
If it exists, print the lexicographically smallest such permutation, with spaces in between.

Sample Input 1

6
1 2
1 3
1 4
1 5
5 6

Sample Output 1

1 2 4 5 3 6

If the permutation (1, 2, 4, 5, 3, 6) is used to generate a tree, it looks as follows:

This is isomorphic to the given graph.

Sample Input 2

6
1 2
2 3
3 4
1 5
5 6

Sample Output 2

1 2 3 4 5 6

Sample Input 3

15
1 2
1 3
2 4
2 5
3 6
3 7
4 8
4 9
5 10
5 11
6 12
6 13
7 14
7 15

Sample Output 3

-1

Solution in C++14 (GCC 5.4.1) (judge verdict: Runtime Error)

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

int n;
vector<int> g[100010];
vector<int> ng[100010];
vector<int> res[2];
bool f[100010];

bool dfs(int v,int pre){
  f[v]=true;
  for(int nv : ng[v]){
    if(nv==pre)continue;
    if(!dfs(nv,v))return false;
  }
  return ng[v].size()<=2;
}

void dfs2(int v,int pre,int num,int idx){
  int lcnt=0;
  for(int nv : g[v]){
    if(nv==pre)continue;
    if(!f[nv]&&g[nv].size()==1)lcnt++;
  }
  res[idx].push_back(num+lcnt);
  for(int nv : g[v]){
    if(nv==pre)continue;
    if(!f[nv]&&g[nv].size()==1){
      res[idx].push_back(num++);
    }
  }
  for(int nv : g[v]){
    if(nv==pre)continue;
    if(!f[v])continue;
    dfs2(nv,v,num+1,idx);
  }
}

int main(){
  cin>>n;
  rep(i,n-1){
    int a,b;
    cin>>a>>b;
    a--;b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  rep(i,n){
    if(g[i].size()==1)continue;
    for(int v : g[i]){
      if(g[v].size()==1||v>i)continue;
      ng[i].push_back(v); ng[v].push_back(i);
    }
  }
  if(!dfs(0,-1)){
    cout<<-1<<endl;
    return 0;
  }
  vector<int> cands;
  rep(i,n){
    if(ng[i].size()==1){
      for(int v : g[i]){
        if(g[v].size()==1){
          cands.push_back(v);
          f[v]=true;
          break;
        }
      }
    }
  }
  vector<int> ans(n,10000000);
  rep(i,cands.size()){
    dfs2(cands[i],-1,0,i);
    vector<int> tmp(n);
    rep(j,n)tmp[res[i][j]]=j;
    res[i]=tmp;
    minch(ans,res[i]);
  }
  rep(i,n)cout<<ans[i]+1<<" ";
  cout<<endl;

  return 0;
}