#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;

const int N = 1e5;
vector<vector<int>> g(N);
using Value = int;
// 戻るかどうか
map<int, Value> dp[N][2];
using P = pair<int, int>;
vector<P> mi0(N, P(0, -1)), mi1(N, P(0, -1));
int calced[N];
int n;
Value dfs(int i, int x, int p, int f = 0) {
  if(dp[i][x].count(p)) return dp[i][x][p];
  int cnt = 0;
  Value res = 0;
  if(f || p == -1) {
    // O(deg(i))
    // go only child
    int mi = 0;
    for(int j : g[i]) if(j != p) {
      cnt++;
      int d = 2 + dfs(j, 1, i, f);
      res += d;
      int m = - d + (1 + dfs(j, 0, i, f));
      mi = min(mi, m);
      if(p == -1 && !calced[i]) {
        P r(m, j);
        if(mi0[i] > r) {
          mi1[i] = mi0[i];
          mi0[i] = r;
        } else if(mi1[i] > r) {
          mi1[i] = r;
        }
      }
    }
    if(p == -1) calced[i] = 1;
    if(!x) {
      res += mi;
    }
  } else {
    // O(1)
    cnt = g[i].size() - 1;
    if(x) {
      res = dfs(i, 1, -1, f);
    } else {
      res = dfs(i, 0, -1, f);
      if(mi0[i].second == p) {
        res -= mi0[i].first;
        res += mi1[i].first;
      }
    }
    res -= 2 + dfs(p, 1, i, f);
  }
  return dp[i][x][p] = res;
}
int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  cin >> n;
  for(int i = 0; i < n - 1; i++) {
    int a, b; cin >> a >> b; a--; b--;
    g[a].emplace_back(b);
    g[b].emplace_back(a);
  }
  dfs(0, 0, -1, 1);
  dfs(0, 1, -1, 1);
  cout << fixed << setprecision(8);
  for(int i = 0; i < n; i++) cout << dfs(i, 0, -1) << endl;
  return 0;
}

