#include <bits/stdc++.h>
using namespace std;
template <typename Value>
class feque {
 protected:
  vector<Value> data;

 public:
  feque() {}
  feque(const feque &f) { data = f.data; }
  feque(feque &&f) { this->data = move(f.data); }
  feque(initializer_list<Value> list) { data = list; }
  feque &operator=(const feque &f) {
    data = f.data;
    return *this;
  }
  feque &operator=(feque &&f) {
    this->data = move(f.data);
    return *this;
  }
  feque &operator=(initializer_list<Value> list) {
    data = list;
    return *this;
  }
  bool empty() const { return data.empty(); }
  size_t size() { return data.size(); }
  Value &front() { return data.back(); }
  const Value &front() const { return data.back(); }
  Value &back() { return data.front(); }
  const Value &back() const { return data.front(); }
  void push(const Value &value) { data.push_back(value); }
  void pop() { data.pop_back(); }
  typename vector<int>::reverse_iterator begin() { return data.rbegin(); }
  typename vector<int>::reverse_iterator end() { return data.rend(); }
  Value &operator[](const int &index) { return data[data.size() - 1 - index]; }
};
const int MAX_N = 1e6;
const int ROOT = 1;
int n;
array<vector<int>, MAX_N + 1> adjacency_list;
array<feque<int>, MAX_N + 1> depth_array;
array<int, MAX_N + 1> dominant_index;
void make_adjacent(const int &v, const int &u) {
  adjacency_list[v].push_back(u);
  adjacency_list[u].push_back(v);
}
bool has_child(const int &vertex) {
  return (vertex != ROOT and adjacency_list[vertex].size() > 1) or
         (vertex == ROOT and not adjacency_list[ROOT].empty());
}
void compute_depth_array(const int &vertex, const int &parent = -1) {
  int deepest_child;
  if (has_child(vertex)) {
    deepest_child = -1;
    for (const int &adjacent : adjacency_list[vertex]) {
      if (adjacent != parent) {
        compute_depth_array(adjacent, vertex);
        if (deepest_child == -1 or
            depth_array[deepest_child].size() < depth_array[adjacent].size())
          deepest_child = adjacent;
      }
    }
    dominant_index[vertex] =
        (depth_array[deepest_child][dominant_index[deepest_child]] > 1
             ? dominant_index[deepest_child] + 1
             : 0);
    swap(depth_array[vertex], depth_array[deepest_child]);
    depth_array[vertex].push(1);
    for (const int &adjacent : adjacency_list[vertex]) {
      if (adjacent != parent and adjacent != deepest_child) {
        for (int depth = 1; depth <= depth_array[adjacent].size(); ++depth) {
          depth_array[vertex][depth] += depth_array[adjacent][depth - 1];
          if (depth_array[vertex][depth] >
                  depth_array[vertex][dominant_index[vertex]] or
              (depth_array[vertex][depth] ==
                   depth_array[vertex][dominant_index[vertex]] and
               depth < dominant_index[vertex])) {
            dominant_index[vertex] = depth;
          }
        }
      }
    }
  } else {
    depth_array[vertex] = {1};
    dominant_index[vertex] = 0;
  }
}
void optimize_IO() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
}
int main() {
  optimize_IO();
  cin >> n;
  for (int i = 1; i <= n - 1; ++i) {
    int x, y;
    cin >> x >> y;
    make_adjacent(x, y);
  }
  compute_depth_array(ROOT);
  for (int vertex = 1; vertex <= n; ++vertex)
    cout << dominant_index[vertex] << ' ';
  cout << '\n';
}
