#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; int n; std::vector node[100001]; int cost[100001]; int main(){ std::cin >> n; rep(i, n)cost[i] = inf; rep(i, n - 1){ int x, y; std::cin >> x >> y; node[x - 1].push_back(y - 1); node[y - 1].push_back(x - 1); } std::queue que; que.push(0); cost[0] = 0; REP(i, 1, n){ if (node[i].size() == 1){ cost[i] = 0; que.push(i); } } while (!que.empty()){ int p = que.front(); que.pop(); int s = node[p].size(); rep(i, s){ int to = node[p][i]; if (cost[to] > cost[p] + 1){ cost[to] = cost[p] + 1; que.push(to); } } } rep(i, n)std::cout << cost[i] << std::endl; return 0; }