#include <bits/stdc++.h>
#define sz(x) ((ll)x.size())
#define PB push_back
#define all(x) x.begin(),x.end()
#define i3 array<ll,3>
#define i2 array<ll,2>
using namespace std;
typedef long double ld;
typedef long long ll;
const ll N = 400100;
const int md = 3;
vector<int> g[N];
int n, dst[N], nxt[N], ans[N], tt = 0;

void dfs(int v, int p){
    dst[v] = 0;
    nxt[v] = -1;

    for (int u : g[v]){
        if (u == p) continue;

        dfs(u, v);

        if (dst[u] + 1 > dst[v]){
            dst[v] = dst[u] + 1;
            nxt[v] = u;
        }
    }
}

void last_dfs(int v, int p){
    ans[v] = ++tt;

    for (int u : g[v]){
        if (u == p || u == nxt[v])
            continue;

        last_dfs(u, v);
    }

    if (nxt[v] != -1)
        last_dfs(nxt[v], v);

    tt++;
}

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

#ifdef _LOCAL
    freopen("in.txt","r",stdin);
#endif // _LOCAL

    cin >> n;

    for (int i = 1; i < n; i++){
        int x, y; cin >> x >> y;

        x--; y--;

        g[x].PB(y);
        g[y].PB(x);
    }

    dfs(0, -1);

    int root = 0;

    while (nxt[root] != -1)
        root = nxt[root];

    dfs(root, -1);
    last_dfs(root, -1);

    for (int i = 0; i < n; i++)
        cout << ans[i] << " ";

    return 0;
}

//雪花飄飄北風嘯嘯
//天地一片蒼茫

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl

#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define lb lower_bound
#define ub upper_bound

#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()

#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
//change less to less_equal for non distinct pbds, but erase will bug

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

int n;
vector<int> al[200005];

vector<ii> v[200005];
int span[200005];
int mn[200005];
int gap[200005];

void dfs(int i,int p){
	int best=-1;
	for (auto &it:al[i]){
		if (it==p) continue;
		
		dfs(it,i);
		if (best==-1 || gap[best]<gap[it]) best=it;
	}
	
	//suibian put i on the edge
	v[i].pub(ii(i,1));
	span[i]=0;
	mn[i]=1;
	gap[i]=0;
	
	for (auto &it:al[i]){
		if (it==p) continue;
		if (it==best) continue;
		
		if (sz(v[i])>sz(v[it])){
			for (auto &it2:v[it]){
				v[i].pub(ii(it2.fi,it2.se-mn[it]+mn[i]+span[i]));
			}
		}
		else{
			for (auto &it2:v[i]){
				v[it].pub(ii(it2.fi,it2.se-mn[i]+mn[it]-span[i]));
			}
			mn[i]=mn[it]-span[i];
			swap(v[i],v[it]);
		}
		
		span[i]+=span[it];
	}
	
	if (best!=-1){
		int it=best;
		
		if (sz(v[i])>sz(v[it])){
			for (auto &it2:v[it]){
				v[i].pub(ii(it2.fi,it2.se-mn[it]+mn[i]+span[i]));
			}
		}
		else{
			for (auto &it2:v[i]){
				v[it].pub(ii(it2.fi,it2.se-mn[i]+mn[it]-span[i]));
			}
			mn[i]=mn[it]-span[i];
			swap(v[i],v[it]);
		}
		
		span[i]+=span[it];
		
		gap[i]=gap[it];
	}
	
	span[i]+=2;
	mn[i]--;
	gap[i]++;
	
	//cout<<mn[i]<<" "<<span[i]<<endl;
	//for (auto &it:v[i]) cout<<it.fi<<"_"<<it.se<<" "; cout<<endl;
	//cout<<endl;
}

int w[200005];
void dfs1(int i,int p){
	for (auto &it:al[i]){
		if (it==p) continue;
		
		w[it]=w[i]+1;
		dfs1(it,i);
	}
}

int ans[200005];

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin.exceptions(ios::badbit | ios::failbit);
	
	cin>>n;
	
	int a,b;
	rep(x,1,n){
		cin>>a>>b;
		
		al[a].pub(b);
		al[b].pub(a);
	}
	
	dfs1(1,-1);
	int root=1;
	rep(x,2,n+1) if (w[x]>w[root]) root=x;
	
	dfs(root,-1);
	
	for (auto &it:v[root]) ans[it.fi]=it.se-mn[root];
	
	rep(x,1,n+1) cout<<ans[x]<<" ";
}
