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

const int MAXN = 2e5;
vector<int> adj[MAXN];
int par[MAXN];
int nbSommets;
int id[MAXN];
bool onPath[MAXN];
int cnt;

int getFurthest(int source) {
  vector<int> dis(nbSommets, -1);
  dis[source] = 0;
  queue<int> q;
  q.push(source);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (auto v : adj[u])
      if (dis[v] == -1) {
        dis[v] = dis[u] + 1;
        par[v] = u;
        q.push(v);
      }
  }
  int sol = 0;
  for (int i(0); i < nbSommets; ++i)
    if (dis[i] > dis[sol])
      sol = i;
  return sol;
}

void dfs(int u, int p) {
  id[u] = ++cnt;
  for (auto v : adj[u])
    if (v != p and !onPath[v])
      dfs(v, u);
  for (auto v : adj[u])
    if (v != p and onPath[v])
      dfs(v, u);
  ++cnt;
}

signed main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  cin >> nbSommets;
  for (int i = 0; i < nbSommets - 1; ++i) {
    int u, v;
    cin >> u >> v;
    --u, --v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }

  int s = getFurthest(0);
  int t = getFurthest(s);
  while (1) {
    onPath[t] = true;
    if (t == s)
      break;
    t = par[t];
  }
  dfs(s, s);
  for (int i = 0; i < nbSommets; ++i) {
    cout << id[i] << ' ';
  }
  cout << endl;
}

#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define maxm 600005 
#define maxn 200005
#define ls (tot << 1)
#define rs (tot << 1 | 1)
#define PII pair<int, int>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
const double pi = acos(-1);
const ll mod = 1e9 + 7;
const double eps = 1e-10;
inline ll read(){
    ll x = 0, f = 1;char ch = getchar();
    while(ch > '9' || ch < '0'){if(ch == '-') f = -1;ch = getchar();}
    while(ch >= '0' && ch <= '9'){x = x * 10 + ch -'0';ch = getchar();}
    return x * f;
}
int n, st, en, dep[maxn], inde[maxn], fa[maxn][20], tot, D[maxn];
struct p{
	int u, v, nxt;
}e[maxn * 2];
void add(int u, int v){e[++tot] = p{u, v, inde[u]}, inde[u] = tot;}
void dfs(int u, int f){
	dep[u] = dep[f] + 1;
	fa[u][0] = f;
	for(int i = 1;i < 20;i++) fa[u][i] = fa[fa[u][i - 1]][i - 1];
	if(dep[u] > dep[st]) st = u;
	for(int i = inde[u];i;i = e[i].nxt){
		int v = e[i].v;
		if(v == f) continue;
		dfs(v, u);
	}
}
int lca(int u, int v){
	if(dep[u] < dep[v]) swap(u, v);
	int t = dep[u] - dep[v];
	for(int i = 19;i >= 0;i--){
		if(t & (1 << i)) u = fa[u][i];
	}
	for(int i = 19;i >= 0;i--){
		if(fa[u][i] != fa[v][i])
			u = fa[u][i], v = fa[v][i];
	}
	if(u == v) return u;
	return fa[u][0];
}
int dfn[maxn], dfs_clock;
int s[maxn], tp;
ll E[maxn];
void dfs2(int u, int f){
	dfn[u] = ++dfs_clock;
	bool F = 0;
	for(int i = inde[u];i;i = e[i].nxt){
		int v = e[i].v;
		if(v == f) continue;
		F = 1;
		dfs2(v, u);
	}
	if(!F) s[++tp] = u;
}
bool cmp(int a, int b){return D[a] < D[b] || (D[a] == D[b] && dfn[a] < dfn[b]);}
int dis(int u, int v){
	return dep[u] + dep[v] - 2 * dep[lca(u, v)];
}
void gfind(int x, ll v){
	if(E[x]) return;
	E[x] = v;
	gfind(fa[x][0], v - 1);
}
bool onzj[maxn];
int getD(int u){
	for(int i = 19;i >= 0;i--){
		if(!onzj[fa[u][i]]) u = fa[u][i];
	}
	return dep[u];
}
int main(){
	n = read();
	for(int i = 1;i < n;i++){
		int u = read(), v = read();
		add(u, v), add(v, u);
	}
	dfs(1, 0);
	en = st;st = 0;
	dfs(en, 0);
	swap(st, en);
	onzj[st] = onzj[0] = 1;
	for(int i = en;i != st;i = fa[i][0]) onzj[i] = 1;
	dfs2(st, 0);
	for(int i = 1;i <= tp;i++){
		if(s[i] == en) D[s[i]] = inf;
		else{
			D[s[i]] = getD(s[i]);
		}
	}
	sort(s + 1, s + tp + 1, cmp);
	s[0] = st;
	E[st] = 1;
	for(int i = 1;i <= tp;i++){
		E[s[i]] = E[s[i - 1]] + dis(s[i], s[i - 1]);
	}
	for(int i = 1;i <= tp;i++){
		gfind(fa[s[i]][0], E[s[i]] - 1);
	}
	for(int i = 1;i <= n;i++) printf("%lld ", E[i]);
	return 0;
}