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

#define fr(i,n) for(int i = 0; i<n; i++)
#define sz(v) (int)(v.size())
#define prin(a) cout << #a << " = " << a << endl
#define prinv(v) cout << #v << " = "; for(auto it : v) cout << it << ", "; cout << endl
#define all(v) (v).begin(),(v).end()

typedef long long ll;

#define rmin(a,b) a = min<ll>(a,b)
#define rmax(a,b) a = max<ll>(a,b)

#define fi first
#define se second

const int N = 2e5+10;

namespace diametro_space{
int n;
vector<int> *g;
 
void dfs(int no, int from, int dac, ll d[]){
	d[no] = dac;
	for(auto it : g[no]){
		if(it!=from) dfs(it,no,dac+1,d);
	}
}
 
int max_dist_glob = 0; // diametro da arvore

int get_most_dist(int no, ll d[]){
	dfs(no,-1,0,d);
	int max_dist_cur = -1;
	int no_max_dist = -1;
	fr(i,n){
		if(d[i]>max_dist_cur){
			max_dist_cur = d[i];
			no_max_dist = i;
		}
	}
	max_dist_glob = max(max_dist_glob,max_dist_cur);
	return no_max_dist;
}

vector<int> nos_diam;

int no0, no1;

//retorna diametro em numero de arestas! (ou seja, vertices -1)
ll find_diametro(vector<int> _g[N], int _n, ll vd[2][N]){
	g = _g;
	n = _n;
	max_dist_glob = 0;
	
	no1 = get_most_dist(0,vd[0]);
	no0 = get_most_dist(no1,vd[1]);
	get_most_dist(no0,vd[0]);
	
	fr(i,n){
		if(vd[0][i]+vd[1][i]==max_dist_glob) nos_diam.push_back(i);
	}
	
	return max_dist_glob;
}

}; //end space diametro

namespace lca_space{
int nlog;
int n;
vector<int> *g;
int pai[N], dist[N]; //pai do nó i (raiz = -1)
int st[N][25]; //sparse table - st[i][j] = pai 2^j niveis acima do nó i

void dfs(int no, int from, int dac){
	dist[no] = dac;
	for(auto it : g[no]){
		if(it==from) continue;
		pai[it] = no;
		dfs(it,no,dac+1);
	}
}

void make(vector<int> _g[N], int _n, int root){
	g = _g;
	n = _n;

	pai[root] = -1;
	dfs(root,-1,0);
	
	nlog = 1;
	while((1<<nlog)<n) nlog++;
	assert(nlog<25);
	
	fr(i,n) fr(j,nlog+1) st[i][j] = -1;
	fr(i,n) st[i][0] = pai[i];
	
	for(int j = 1; j<=nlog; j++){
		fr(i,n){
		    int ant_pai = st[i][j-1];
		    if(ant_pai!=-1) st[i][j] = st[ant_pai][j-1];
		}
	}
}

int lca(int p, int q){
	if(dist[p]<dist[q]) swap(p,q);
	for(int i = nlog; i>=0;i--){
		if(dist[p]-dist[q] >= (1<<i) ) p = st[p][i];	
	}
	if(p==q) return p;
	for(int i = nlog; i>=0; i--){
		if(st[p][i]!=st[q][i]){
			p = st[p][i];
			q = st[q][i];
		}
	}
	return pai[q];
}	

int get_dist(int u, int v){
	return dist[u]+dist[v]-2*dist[lca(u,v)];
}

};

int ehdiam[N];
vector<int> g[N];
ll vdist[2][N];

struct cmp{
bool operator()(int a, int b){
	return ehdiam[a]<ehdiam[b];
}
};

ll cor = 1;
int ultno = -1;
ll vcor[N];

void dfs(int no, int from){
	if(from!=-1){
		cor+=lca_space::get_dist(ultno,no);
	}
	vcor[no] = cor;
	ultno = no;
	for(auto &it : g[no]){
		if(it==from) continue;
		dfs(it,no);
	}
	
}

int main(){
	ios::sync_with_stdio(0); cin.tie(0);
	int n; cin >> n;
	fr(i,n-1){
		int a, b; cin >> a >> b; a--,b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	
	//prin(n);
	
	diametro_space::find_diametro(g,n,vdist);
	vector<int> nos_diam = diametro_space::nos_diam;
	int root = diametro_space::no0;
	for(auto &i : nos_diam) ehdiam[i] = 1;
	
	fr(i,n) sort(all(g[i]),cmp());
	
	lca_space::make(g,n,root);
	
	//prinv(nos_diam);
	
	dfs(root,-1);
	
	fr(i,n){
		if(i) cout << " ";
		cout << vcor[i];
	}
	cout << "\n";
}
#include <bits/stdc++.h>
using namespace std;
#define deb(k) cerr << #k << ": " << k << "\n";
#define size(a) (int)a.size()
#define fastcin cin.tie(0)->sync_with_stdio(0);
#define st first
#define nd second
#define pb push_back
#define mk make_pair
#define int long long
typedef long double ldbl;
typedef double dbl;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<double, pii> pdii;
typedef pair<ll, ll> pll;
typedef map<int, int> mii;
typedef vector<int> vint;
#define MAXN 300100
#define MAXLG 20
const int inf = 0x3f3f3f3f;
const ll mod = 1000000007;
const ll linf = 0x3f3f3f3f3f3f3f3f;
const int N = 300100;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int d[N];
vint g[N];
int cnt = 1;
int ans[N];
int pai[N];
set<int>dia;
vint cur;

void dfs(int x, int p = -1, int u = 1){
	d[x] = u;
	pai[x] = p;
	ans[x] = cnt;
	for(auto v : g[x]){
		if(v == p) continue;
		if(dia.count(v)) continue;
		cnt++;
		dfs(v, x, u+1);
	}
	if(dia.count(x) && !cur.empty()){
		int v = cur.back();
		cur.pop_back();
		cnt++;
		dfs(v, x, u+1);
	}

	cnt++;
}

void solve(){
	int n;
	cin>>n;
	for(int i=1;i<n;i++){
		int a,b;
		cin>>a>>b;
		g[a].pb(b);
		g[b].pb(a);
	}
	dfs(1);
	int mx = 0, ind = -1;
	for(int i=1;i<=n;i++){
		if(d[i] > mx){
			mx = d[i];
			ind  = i;
		}
	}
	cnt = 1;
	int root = ind;
	dfs(root);
	mx = 0, ind = -1;
	for(int i=1;i<=n;i++){
		if(d[i] > mx){
			mx = d[i];
			ind = i;
		}
	}
	int aux = ind;
	while(aux != -1){
		cur.pb(aux);
		dia.insert(aux);
		aux = pai[aux];
	}
	cur.pop_back();
	cnt = 1;
	dfs(root);
	for(int i=1;i<=n;i++) cout<<ans[i]<<" ";
	cout<<"\n";








	// Have you read the problem again?
	// Maybe you understood the wrong problem
}

int32_t main(){
	fastcin;
	int t_ = 1;
	//cin>>t_;
	while(t_--)
		solve();
	return 0;
}
