#include <cstdio>
#include <cstdint>
#include <cstddef>
#include <vector>
#include <algorithm>
#include <utility>
#include <limits>
#include <type_traits>
#include <tuple>

template <typename F>
class fix_point: F {
public:
  explicit constexpr fix_point(F&& f) noexcept: F(std::forward<F>(f)) {}

  template <typename... Args>
  constexpr decltype(auto) operator ()(Args&&... args) const {
    return F::operator ()(*this, std::forward<Args>(args)...);
  }
};

template <typename F>
static inline constexpr decltype(auto) make_fix_point(F&& f) noexcept {
  return fix_point<F>{std::forward<F>(f)};
}

template <typename WeightType>
class weighted_edge {
public:
  using size_type = size_t;
  using weight_type = WeightType;

protected:
  size_type M_src, M_dst;
  weight_type M_weight;

public:
  weighted_edge() = default;
  weighted_edge(weighted_edge const&) = default;
  weighted_edge(weighted_edge&&) = default;

  weighted_edge(size_type s, size_type d, weight_type w):
    M_src(s), M_dst(d), M_weight(w)
  {}

  weighted_edge& operator =(weighted_edge const&) = default;
  weighted_edge& operator =(weighted_edge&&) = default;

  bool operator <(weighted_edge const& other) const {
    if (M_weight < other.M_weight) return true;
    if (other.M_weight < M_weight) return false;
    if (M_src != other.M_src) return M_src < other.M_src;
    return M_dst < other.M_dst;
  }

  size_type source() const { return M_src; }
  size_type target() const { return M_dst; }
  weight_type weight() const { return M_weight; }
};

struct directed_tag {};
struct undirected_tag {};

template <typename Edge, typename Directedness>
class adjacency_list {
public:
  using size_type = size_t;
  using edge_type = Edge;
  using weight_type = typename Edge::weight_type;
  static constexpr weight_type inf = std::numeric_limits<weight_type>::max();

private:
  std::vector<std::vector<edge_type>> M_g;

public:
  adjacency_list() = default;
  adjacency_list(adjacency_list const&) = default;
  adjacency_list(adjacency_list&&) = default;
  adjacency_list(size_type n): M_g(n) {}

  template <typename... Args>
  void emplace(size_type src, size_type dst, Args... args) {
    M_g[src].emplace_back(src, dst, args...);
    if (std::is_same<Directedness, undirected_tag>::value)
      M_g[dst].emplace_back(dst, src, args...);
  }

  void sort_by_index() {
    auto cmp = [](auto const& e1, auto const& e2) {
      return e1.target() < e2.target();
    };
    for (auto v: M_g) std::sort(v.begin(), v.end(), cmp);
  }

  size_type size() const { return M_g.size(); }
  std::vector<edge_type> const& operator [](size_type i) const { return M_g[i]; }
};

template <typename Edge, typename Directedness>
constexpr typename Edge::weight_type inf = adjacency_list<Edge, Directedness>::inf;

constexpr intmax_t  operator ""_jd(unsigned long long n) { return n; }
constexpr uintmax_t operator ""_ju(unsigned long long n) { return n; }
constexpr size_t    operator ""_zu(unsigned long long n) { return n; }
// constexpr ptrdiff_t operator ""_td(unsigned long long n) { return n; }

template <typename Monoid, typename UndirectedTree>
auto dp_on_tree(UndirectedTree const& g) {
  Monoid e{};
  size_t n = g.size();
  std::vector<size_t> parent(n, -1_zu);

  std::vector<std::vector<Monoid>> dp0(n), dp1(n);
  std::vector<Monoid> dp(n);
  for (size_t i = 0; i < n; ++i) {
    dp0[i].resize(g[i].size()+1, e);
    dp1[i].resize(g[i].size()+1, e);
  }

  make_fix_point([&](auto dfs0, size_t v, size_t p) -> Monoid {
      Monoid res = e;
      typename UndirectedTree::weight_type weight{};
      for (size_t i = 0; i < g[v].size(); ++i) {
        size_t u = g[v][i].target();
        if (u == p) {
          parent[v] = i;
          weight = g[v][i].weight();
          continue;
        }
        Monoid tmp = dfs0(u, v);
        res.append(tmp);
        dp0[v][i+1] = dp1[v][i] = tmp;
      }
      return res.f(weight);
  })(0, -1_zu);

  make_fix_point([&](auto dfs1, size_t v, size_t p, size_t pi) -> void {
      if (v != 0) {
        Monoid tmp = (dp0[p][pi] + dp1[p][pi+1]).f(g[p][pi].weight());
        dp0[v][parent[v]+1] = tmp;
        dp1[v][parent[v]] = tmp;
      }
      {
        for (size_t i = 1; i < dp0[v].size(); ++i)
          dp0[v][i].prepend(dp0[v][i-1]);
        for (size_t i = dp1[v].size()-1; i--;)
          dp1[v][i].append(dp1[v][i+1]);
        dp[v] = dp1[v][0];
      }
      for (size_t i = 0; i < g[v].size(); ++i) {
        size_t u = g[v][i].target();
        if (u != p) dfs1(u, v, i);
      }
  })(0, -1_zu, -1_zu);

  return dp;
}

class distance {
public:
  using value_type = int;

private:
  value_type M_value = 0;

public:
  distance() = default;
  distance(distance const&) = default;
  distance(distance&&) = default;
  distance(value_type v): M_value(v) {}

  distance& operator =(distance const&) = default;
  distance& operator =(distance&&) = default;

  distance& append(distance const& other) {
    M_value = std::max(other.M_value, M_value);
    return *this;
  }
  distance& prepend(distance const& other) {
    M_value = std::max(M_value, other.M_value);
    return *this;
  }
  distance operator +(distance const& other) const {
    return distance(*this).append(other);
  }
  template <typename Tp>
  distance f(Tp const& x) const { return distance(M_value + x); }
  value_type get() const { return M_value; }
};

int main() {
  size_t n;
  scanf("%zu", &n);

  adjacency_list<weighted_edge<int>, undirected_tag> g(n);
  for (size_t i = 1; i < n; ++i) {
    size_t u, v;
    scanf("%zu %zu", &u, &v);
    --u, --v;
    g.emplace(u, v, 1);
  }
  g.sort_by_index();

  int whole = 2*(n-1);
  for (auto r: dp_on_tree<distance>(g))
    printf("%d\n", whole-r.get());
}



Measured memory_bytes: 31448