#include<bits/stdc++.h>
using namespace std;
int n,x,y;
int fir[100005],nxt[200005],to[200005],cnt;
int dp[100005][2],son[100005][2],ans,S;
int a[100005],tot,vis[100005],b[100005],Ans[2][100005];

int read(){
	int x=0;char ch=getchar();
	while(!isdigit(ch)) ch=getchar();
	while(isdigit(ch)) x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return x;
}

void DP(int x,int f){
	for(int i=fir[x];i;i=nxt[i]){
		if(to[i]==f) continue;
		DP(to[i],x);
		if(dp[to[i]][0]+1>dp[x][0]){
			dp[x][1]=dp[x][0],son[x][1]=son[x][0];
			dp[x][0]=dp[to[i]][0]+1,son[x][0]=to[i];
		}
		else if(dp[to[i]][0]+1>dp[x][1]) dp[x][1]=dp[to[i]][0]+1,son[x][1]=to[i];
	}
	if(ans<dp[x][0]+dp[x][1]+1) ans=dp[x][0]+dp[x][1]+1,S=x;
}

void lian(int x,int op){
	vis[x]=1;
	if(op) a[++tot]=x;
	if(son[x][0]) lian(son[x][0],op);
	if(!op) a[++tot]=x;
}

void dfs(int x,int pos,int dep){
	if(dep>1){puts("-1");exit(0);}
	b[pos]++,vis[x]=1;
	for(int i=fir[x];i;i=nxt[i]) if(!vis[to[i]]) dfs(to[i],pos,dep+1);
}

int com(){
	for(int i=1;i<=n;i++){
		if(Ans[0][i]<Ans[1][i]) return 0;
		if(Ans[0][i]>Ans[1][i]) return 1;
	}
	return 0;
}

int main(){
	n=read();
	for(int i=1;i<n;i++){
		x=read(),y=read();
		to[++cnt]=y,nxt[cnt]=fir[x],fir[x]=cnt;
		to[++cnt]=x,nxt[cnt]=fir[y],fir[y]=cnt;
	}
	DP(1,0);
	if(son[S][0]) lian(son[S][0],0);
	a[++tot]=S,vis[S]=1;
	if(son[S][1]) lian(son[S][1],1);
	for(int i=1;i<=tot;i++) dfs(a[i],i,0);
	int s=0;
	for(int i=1;i<=tot;i++){
		for(int j=s+1;j<s+b[i];j++) Ans[0][j]=j+1;
		Ans[0][s+b[i]]=s+1,s+=b[i];
	}
	s=0;
	for(int i=tot;i>=1;i--){
		for(int j=s+1;j<s+b[i];j++) Ans[1][j]=j+1;
		Ans[1][s+b[i]]=s+1,s+=b[i];
	}
	int id=com();
	for(int i=1;i<=n;i++) printf("%d ",Ans[id][i]);

	return 0;
}
### Prompt

Please formulate a Cpp solution to the following problem:

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.

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.

Examples

Input

6
1 2
1 3
1 4
1 5
5 6


Output

1 2 4 5 3 6


Input

6
1 2
2 3
3 4
1 5
5 6


Output

1 2 3 4 5 6


Input

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


Output

-1

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
int n,x,y;
int fir[100005],nxt[200005],to[200005],cnt;
int dp[100005][2],son[100005][2],ans,S;
int a[100005],tot,vis[100005],b[100005],Ans[2][100005];

int read(){
	int x=0;char ch=getchar();
	while(!isdigit(ch)) ch=getchar();
	while(isdigit(ch)) x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return x;
}

void DP(int x,int f){
	for(int i=fir[x];i;i=nxt[i]){
		if(to[i]==f) continue;
		DP(to[i],x);
		if(dp[to[i]][0]+1>dp[x][0]){
			dp[x][1]=dp[x][0],son[x][1]=son[x][0];
			dp[x][0]=dp[to[i]][0]+1,son[x][0]=to[i];
		}
		else if(dp[to[i]][0]+1>dp[x][1]) dp[x][1]=dp[to[i]][0]+1,son[x][1]=to[i];
	}
	if(ans<dp[x][0]+dp[x][1]+1) ans=dp[x][0]+dp[x][1]+1,S=x;
}

void lian(int x,int op){
	vis[x]=1;
	if(op) a[++tot]=x;
	if(son[x][0]) lian(son[x][0],op);
	if(!op) a[++tot]=x;
}

void dfs(int x,int pos,int dep){
	if(dep>1){puts("-1");exit(0);}
	b[pos]++,vis[x]=1;
	for(int i=fir[x];i;i=nxt[i]) if(!vis[to[i]]) dfs(to[i],pos,dep+1);
}

int com(){
	for(int i=1;i<=n;i++){
		if(Ans[0][i]<Ans[1][i]) return 0;
		if(Ans[0][i]>Ans[1][i]) return 1;
	}
	return 0;
}

int main(){
	n=read();
	for(int i=1;i<n;i++){
		x=read(),y=read();
		to[++cnt]=y,nxt[cnt]=fir[x],fir[x]=cnt;
		to[++cnt]=x,nxt[cnt]=fir[y],fir[y]=cnt;
	}
	DP(1,0);
	if(son[S][0]) lian(son[S][0],0);
	a[++tot]=S,vis[S]=1;
	if(son[S][1]) lian(son[S][1],1);
	for(int i=1;i<=tot;i++) dfs(a[i],i,0);
	int s=0;
	for(int i=1;i<=tot;i++){
		for(int j=s+1;j<s+b[i];j++) Ans[0][j]=j+1;
		Ans[0][s+b[i]]=s+1,s+=b[i];
	}
	s=0;
	for(int i=tot;i>=1;i--){
		for(int j=s+1;j<s+b[i];j++) Ans[1][j]=j+1;
		Ans[1][s+b[i]]=s+1,s+=b[i];
	}
	int id=com();
	for(int i=1;i<=n;i++) printf("%d ",Ans[id][i]);

	return 0;
}
```