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

const int N = 2e5 + 10;

int n, d[N], ans[N], last, fa[N], rt, st, mxd[N];

vector <int> e[N];

void dfs1_(int u) {
	mxd[u] = d[u] = d[fa[u]] + 1;
	
	for (int v, i = 0; i < (int) e[u].size(); i++) {
		v = e[u][i];
		
		if (v == fa[u]) continue;
		
		fa[v] = u, dfs1_(v), mxd[u] = max(mxd[u], mxd[v]);
	}
	
	if (d[u] > d[rt]) rt = u;
}

bool cmp_(int u, int v) {
	return mxd[u] < mxd[v];
}

void dfs2_(int u) {
	last = u;
	sort(e[u].begin(), e[u].end(), cmp_);
	
	for (int v, i = 0; i < (int) e[u].size(); i++) {
		v = e[u][i];
		
		if (v == fa[u]) continue;
		
		ans[v] = ans[last] + d[last] + d[v] - d[u]*2;	
		dfs2_(v);
	}
}

int main() {
	scanf("%d", &n);
	
	for (int u, v, i = 1; i < n; i++) 
		scanf("%d%d", &u, &v), e[u].push_back(v), e[v].push_back(u);
	
	dfs1_(1), st = rt;
	fa[st] = 0, dfs1_(st);
	
	ans[st] = 1, dfs2_(st);
	
	for (int i = 1; i <= n; i++)
		printf("%d ", ans[i]);
}
/**
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡀⠀⠀⠀⠀⢀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⡖⠁⠀⠀⠀⠀⠀⠀⠈⢲⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⣼⡏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢹⣧⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⣸⣿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⣿⣇⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⣿⣿⡇⠀⢀⣀⣤⣤⣤⣤⣀⡀⠀⢸⣿⣿⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⢻⣿⣿⣔⢿⡿⠟⠛⠛⠻⢿⡿⣢⣿⣿⡟⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣀⣤⣶⣾⣿⣿⣿⣷⣤⣀⡀⢀⣀⣤⣾⣿⣿⣿⣷⣶⣤⡀⠀⠀⠀⠀
⠀⠀⢠⣾⣿⡿⠿⠿⠿⣿⣿⣿⣿⡿⠏⠻⢿⣿⣿⣿⣿⠿⠿⠿⢿⣿⣷⡀⠀⠀
⠀⢠⡿⠋⠁⠀⠀⢸⣿⡇⠉⠻⣿⠇⠀⠀⠸⣿⡿⠋⢰⣿⡇⠀⠀⠈⠙⢿⡄⠀
⠀⡿⠁⠀⠀⠀⠀⠘⣿⣷⡀⠀⠰⣿⣶⣶⣿⡎⠀⢀⣾⣿⠇⠀⠀⠀⠀⠈⢿⠀
⠀⡇⠀⠀⠀⠀⠀⠀⠹⣿⣷⣄⠀⣿⣿⣿⣿⠀⣠⣾⣿⠏⠀⠀⠀⠀⠀⠀⢸⠀
⠀⠁⠀⠀⠀⠀⠀⠀⠀⠈⠻⢿⢇⣿⣿⣿⣿⡸⣿⠟⠁⠀⠀⠀⠀⠀⠀⠀⠈⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣼⣿⣿⣿⣿⣧⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠐⢤⣀⣀⢀⣀⣠⣴⣿⣿⠿⠋⠙⠿⣿⣿⣦⣄⣀⠀⠀⣀⡠⠂⠀⠀⠀
⠀⠀⠀⠀⠀⠈⠉⠛⠛⠛⠛⠉⠀⠀⠀⠀⠀⠈⠉⠛⠛⠛⠛⠋⠁⠀⠀
**/
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define nl cout<<"\n";
#define ll long long int
#define ld double
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define F(i,a,b) for(i=a;i<b;i++)
//#include <ext/pb_ds/assoc_container.hpp> // policy based data structure header files
//#include <ext/pb_ds/tree_policy.hpp> // policy based data structure header files
#define IOS ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
//using namespace __gnu_pbds; // for pbds
//#define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> // have functions like order_of_key, find_by_order
const double PI = 3.14159265358979323846264338327950288419716939937510582097494459230781641;
const ll M=1e18;
const ll MAXN=200200;
ll i,j,mask;
vector<vector<ll> > v(MAXN);
vector<ll> dist(MAXN), par(MAXN), ans(MAXN), vis(MAXN);
ll val=1;
void dfs0(ll p)
{
    for(auto x:v[p]) {
        if(x!=par[p]) {
            par[x]=p;
            dist[x]=dist[p]+1;
            dfs0(x);
        }
    }
}
void dfs(ll p, ll parent, ll f)
{
    if(ans[p]==0) {
        ans[p]=val;
        val++;
    }
    if(f) {
        for(auto x:v[p]) {
            if(x!=parent) {
                dfs(x, p,1);
            }
        }
        val++;
        return ;
    }
    ll node=0;
    for(auto x:v[p]) {
        if(x!=parent) {
            if(vis[x]) {
                node=x;
            } else {
                dfs(x, p, 1);
                //val++;
            }
        }
    }
    if(node!=0) {
        dfs(node, p, 0);
    }
}
void solve()
{
    ll n;
    cin>>n;
    F(i,0,n-1) {
        ll x,y;
        cin>>x>>y;
        v[x].pb(y);
        v[y].pb(x);
    }
    dfs0(1);
    ll node=0, maxx=0;
    F(i,1,n+1) {
        if(dist[i]>maxx) {
            maxx=dist[i];
            node=i;
        }
    }
    //cout<<node;nl
    dist[node]=0;
    par[node]=0;
    dfs0(node);
    maxx=0;
    F(i,1,n+1) {
        if(dist[i]>maxx) {
            maxx=dist[i];
            node=i;
        }
    }
    //cout<<node;nl
    while(par[node]!=0) {
        vis[node]=1;
        node=par[node];
    }
    //cout<<node;nl
    vis[node]=1;
    dfs(node, -1, 0);
    F(i, 1, n+1) {
        cout<<ans[i]<<" ";
    }
}
int main()
{
    IOS
    /*#ifndef ONLINE_JUDGE
       freopen("input.txt","r",stdin);
       freopen("output.txt","w",stdout);
    #endif // ONLINE_JUDGE*/
    ll t,test=1;
    //cin>>test;
    F(t,1,test+1) {
        //cout<<"Case #"<<t<<": ";
        solve();
        nl
    }
    return 0;
}
