// Template
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <tuple>
#include <utility>
#include <queue>
#include <set>
#include <map>
#define rep_override(x, y, z, name, ...) name
#define rep2(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep3(i, l, r) for (int i = (int)(l); i < (int)(r); ++i)
#define rep(...) rep_override(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll infll = 3003003003003003003LL;
template <typename T>
inline bool chmin(T &x, const T &y) {
    if (x > y) {
        x = y;
        return true;
    }
    return false;
}
template <typename T> 
inline bool chmax(T &x, const T &y) {
    if (x < y) {
        x = y;
        return true;
    }
    return false;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &element : vec) is >> element;
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    for (int i = 0, vec_len = (int)vec.size(); i < vec_len; ++i) {
        os << vec[i] << (i + 1 == vec_len ? "" : " ");
    }
    return os;
}
struct IOSET {
    IOSET() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
    }
} ioset;

// Main
pair<int, int> di(const vector<vector<int>> &g) {
    int u = 0, v = 0;
    {
        vector<int> d1(g.size(), -1);
        queue<int> q;
        q.push(0);
        d1[0] = 0;
        while (!q.empty()) {
            int x = q.front();
            q.pop();
            for (int y : g[x]) {
                if (d1[y] == -1) {
                    d1[y] = d1[x] + 1;
                    q.push(y);
                }
            }
        }
        int mx = 0;
        rep(i, g.size()) if (chmax(mx, d1[i])) u = i;
    }
    {
        vector<int> d1(g.size(), -1);
        queue<int> q;
        q.push(u);
        d1[u] = 0;
        while (!q.empty()) {
            int x = q.front();
            q.pop();
            for (int y : g[x]) {
                if (d1[y] == -1) {
                    d1[y] = d1[x] + 1;
                    q.push(y);
                }
            }
        }
        int mx = 0;
        rep(i, g.size()) if (chmax(mx, d1[i])) v = i;
    }
    return {u, v};
}
int main() {
    int n;
    cin >> n;
    vector<vector<int>> g(n);
    rep(i, n - 1) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    
    auto [u, v] = di(g);
    
    vector<int> mark(n, 0);
    vector<int> prv(n, -1);
    {
        queue<int> q;
        q.push(u);
        while (!q.empty()) {
            int x = q.front();
            q.pop();
            for (int y : g[x]) {
                if (y != prv[x]) {
                    prv[y] = x;
                    q.push(y);
                }
            }
        }
        int cur = v;
        mark[cur] = 1;
        while (cur != u) {
            cur = prv[cur];
            mark[cur] = 1;
        }
    }
    
    vector<int> ans(n);
    {
        int cur = 1;
        auto dfs = [&](auto &&dfs, int x) -> void {
            ans[x] = cur;
            for (int y : g[x]) {
                if (y != prv[x] && !mark[y]) {
                    ++cur;
                    dfs(dfs, y);
                    ++cur;
                }
            }
            for (int y : g[x]) {
                if (y != prv[x] && mark[y]) {
                    ++cur;
                    dfs(dfs, y);
                    ++cur;
                }
            }
        };
        dfs(dfs, u);
    }
    cout << ans << "\n";
}
#include <bits/stdc++.h>
#define fi first
#define se second
#define sz(v) ((int)v.size())
#define all(v) (v).begin(), (v).end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
int n;
int S,E;
int ans[200010],cur;
bool chk[200010];
vector<int> g[200010];
pii dfs(int p,int u) {
	pii r={0,u};
	for(auto& v:g[u]) {
		if(v==p)continue;
		pii rr=dfs(u,v);
		r=max(r,{rr.fi+1,rr.se});
	}
	return r;
}
bool F(int p,int u) {
	chk[u]=true;
	if(u==E)return true;
	for(auto& v:g[u]) {
		if(v==p)continue;
		if(F(u,v))return true;
	}
	chk[u]=false;
	return false;
}
void G(int p,int u) {
	ans[u]=++cur;
	for(auto& v:g[u]) {
		if(v==p||chk[v])continue;
		G(u,v);
		++cur;
	}
	for(auto& v:g[u]) {
		if(v==p)continue;
		if(chk[v]) {
			G(u,v);
			++cur;
		}
	}
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int i,j;
	cin>>n;
	for(i=0;i<n-1;i++) {
		int u,v;cin>>u>>v;
		g[u].pb(v);
		g[v].pb(u);
	}
	S=dfs(1,1).se;
	E=dfs(S,S).se;
	F(S,S);
	G(S,S);
	for(i=1;i<=n;i++) {
		cout<<ans[i]<<' ';
	}
	return 0;
}