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

std::pair<int, std::vector<int>> tree_diameter(const std::vector<std::vector<int>>& G) {
    std::vector<int> to(G.size());

    auto dfs = [&](const auto& dfs, int v, int p) -> std::pair<int, int> {
        std::pair<int, int> ret(0, v);
        for (int c : G[v]) {
            if (c == p) continue;
            auto weight = dfs(dfs, c, v);
            ++weight.first;
            if (ret < weight) {
                ret = weight;
                to[v] = c;
            }
        }
        return ret;
    };

    auto p = dfs(dfs, 0, -1);
    auto q = dfs(dfs, p.second, -1);
    std::vector<int> path;
    int v = p.second;
    while (v != q.second) {
        path.push_back(v);
        v = to[v];
    }
    path.push_back(v);
    return {q.first, path};
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    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> path = tree_diameter(G).second;
    vector<int> nxt(N, -1), ans(N);
    for (int i = 0; i < path.size() - 1; ++i) nxt[path[i]] = path[i+1];
    int k = 1;

    auto dfs = [&](auto& dfs, int v, int p) -> void {
        ans[v] = k;
        for (int c : G[v]) {
            if (c == p || c == nxt[v]) continue;
            k++;
            dfs(dfs, c, v);
        }
        if (nxt[v] != -1) {
            k++;
            dfs(dfs, nxt[v], v);
        }
        k++;
    };

    dfs(dfs, path[0], -1);
    for (int i = 0; i < N; ++i) cout << ans[i] << (i < N - 1 ? " " : "\n");
}
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, a, b) for (int i = b; i >= a; i--)
 
using namespace std;	

const int N = 200111;

int n, s, t, sub[N], ans[N], e = 1;
vector<int> g[N];

pair<int, int> dfs(int v, int p) {
	pair<int, int> a = {0, v};
	for (auto u : g[v]) {
		if (u != p) {
			auto b = dfs(u, v);
			b.first++;
			a = max(a, b);
		}
	}
	return a;
}

void go(int v, int p) {
	sub[v] = (v == t);
	for (auto u : g[v])
		if (u != p) {
			go(u, v);
			sub[v] |= sub[u];
		}
}

void solve(int v, int p) {
	ans[v] = e;
	sort(g[v].begin(), g[v].end(), [&](int a, int b) {
		return sub[a] < sub[b];
	});
	for (auto u : g[v]) 
		if (u != p) {
			e++;
			solve(u, v);
		}
	e++;
}

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	cin >> n;
	rep(i, 1, n - 1) {
		int a, b;
		cin >> a >> b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	
	s = dfs(1, 0).second;
	t = dfs(s, 0).second;
	
	go(s, 0);
	solve(s, 0);
	
	rep(i, 1, n)
		cout << ans[i] << " ";	
	return 0;
}
