#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
const int inf = 1012345678;
vector<int> shortest_path(int src, vector<vector<int> >& G) {
	vector<int> dist(G.size(), inf);
	dist[src] = 0;
	queue<int> que;
	que.push(src);
	while (!que.empty()) {
		int u = que.front(); que.pop();
		for (int i : G[u]) {
			if (dist[i] == inf) {
				dist[i] = dist[u] + 1;
				que.push(i);
			}
		}
	}
	return dist;
}
bool dfs(int pos, int pre, int tar, vector<vector<int> >& G, vector<int>& holder) {
	if (pos == tar) {
		holder.push_back(pos);
		return true;
	}
	for (int i : G[pos]) {
		if (i != pre && dfs(i, pos, tar, G, holder)) {
			holder.push_back(pos);
			return true;
		}
	}
	return false;
}
vector<int> getperm(int n, vector<int> cnt) {
	vector<int> ans;
	int sum = 0;
	for (int i = 0; i < cnt.size(); ++i) {
		for (int j = 1; j <= cnt[i]; ++j) {
			ans.push_back(sum + j);
		}
		ans.push_back(sum);
		sum += cnt[i] + 1;
	}
	return ans;
}
int main() {
	int N;
	cin >> N;
	vector<vector<int> > G(N);
	for (int i = 0; i < N - 1; ++i) {
		int a, b;
		cin >> a >> b; --a, --b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	vector<int> d1 = shortest_path(0, G);
	int v1 = max_element(d1.begin(), d1.end()) - d1.begin();
	vector<int> d2 = shortest_path(v1, G);
	int v2 = max_element(d2.begin(), d2.end()) - d2.begin();
	vector<int> path;
	dfs(v1, -1, v2, G, path);
	vector<int> cnt(path.size(), 0);
	vector<bool> used(N, false);
	for (int i : path) used[i] = true;
	int all = path.size();
	for (int i = 0; i < path.size(); ++i) {
		for (int j : G[path[i]]) {
			if (!used[j]) {
				++cnt[i];
				++all;
			}
		}
	}
	if (all != N) {
		cout << -1 << endl;
	}
	else {
		vector<int> p1 = getperm(N, cnt);
		reverse(cnt.begin(), cnt.end());
		vector<int> p2 = getperm(N, cnt);
		vector<int> ans = min(p1, p2);
		for (int i = 0; i < N; ++i) {
			if (i) cout << ' ';
			cout << ans[i] + 1;
		}
		cout << endl;
	}
	return 0;
}
### Prompt

Construct a CPP code solution to the problem outlined:

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 <queue>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
const int inf = 1012345678;
vector<int> shortest_path(int src, vector<vector<int> >& G) {
	vector<int> dist(G.size(), inf);
	dist[src] = 0;
	queue<int> que;
	que.push(src);
	while (!que.empty()) {
		int u = que.front(); que.pop();
		for (int i : G[u]) {
			if (dist[i] == inf) {
				dist[i] = dist[u] + 1;
				que.push(i);
			}
		}
	}
	return dist;
}
bool dfs(int pos, int pre, int tar, vector<vector<int> >& G, vector<int>& holder) {
	if (pos == tar) {
		holder.push_back(pos);
		return true;
	}
	for (int i : G[pos]) {
		if (i != pre && dfs(i, pos, tar, G, holder)) {
			holder.push_back(pos);
			return true;
		}
	}
	return false;
}
vector<int> getperm(int n, vector<int> cnt) {
	vector<int> ans;
	int sum = 0;
	for (int i = 0; i < cnt.size(); ++i) {
		for (int j = 1; j <= cnt[i]; ++j) {
			ans.push_back(sum + j);
		}
		ans.push_back(sum);
		sum += cnt[i] + 1;
	}
	return ans;
}
int main() {
	int N;
	cin >> N;
	vector<vector<int> > G(N);
	for (int i = 0; i < N - 1; ++i) {
		int a, b;
		cin >> a >> b; --a, --b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	vector<int> d1 = shortest_path(0, G);
	int v1 = max_element(d1.begin(), d1.end()) - d1.begin();
	vector<int> d2 = shortest_path(v1, G);
	int v2 = max_element(d2.begin(), d2.end()) - d2.begin();
	vector<int> path;
	dfs(v1, -1, v2, G, path);
	vector<int> cnt(path.size(), 0);
	vector<bool> used(N, false);
	for (int i : path) used[i] = true;
	int all = path.size();
	for (int i = 0; i < path.size(); ++i) {
		for (int j : G[path[i]]) {
			if (!used[j]) {
				++cnt[i];
				++all;
			}
		}
	}
	if (all != N) {
		cout << -1 << endl;
	}
	else {
		vector<int> p1 = getperm(N, cnt);
		reverse(cnt.begin(), cnt.end());
		vector<int> p2 = getperm(N, cnt);
		vector<int> ans = min(p1, p2);
		for (int i = 0; i < N; ++i) {
			if (i) cout << ' ';
			cout << ans[i] + 1;
		}
		cout << endl;
	}
	return 0;
}
```