#include #include #include #include #include #include #include #include #include #include #define rep(i, a) REP(i, 0, a) #define REP(i, a, b) for(int i = a; i < b; ++i) typedef long long ll; typedef unsigned long long ull; typedef std::pair P; typedef std::pair PP; struct edge{ int to, time, cost; }; const double esp = 1e-9; const int inf = (int)1e+9; struct Node{ int ans = inf; bool used = false; std::vector v; }; int n; Node node[100001]; void updata(Node &n, int k){ if (n.used)return; n.used = true; n.ans = std::min(n.ans, k); int s = n.v.size(); rep(i, s)updata(*n.v[i], k + 1); } int main(){ std::cin >> n; rep(i, n - 1){ int x, y; std::cin >> x >> y; node[x - 1].v.push_back(&node[y - 1]); node[y - 1].v.push_back(&node[x - 1]); } updata(node[0], 0); rep(i, n){ rep(j, n)node[j].used = false; if (node[i].v.size() == 1)updata(node[i], 0); } rep(i, n)std::cout << node[i].ans << std::endl; return 0; }