#include using namespace std; const int INF = 1<<28; int n; vector g[100000]; int dist[100000]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 0; i < n-1; i++) { int x, y; cin >> x >> y; --x, --y; g[x].push_back(y); g[y].push_back(x); } fill(dist, dist + n, INF); queue q; for (int i = 0; i < n; i++) { if (i == 0 || g[i].size() == 1) { q.push(i); dist[i] = 0; } } while (!q.empty()) { int v = q.front(); q.pop(); for (int w: g[v]) { if (dist[w] == INF) { dist[w] = dist[v] + 1; q.push(w); } } } for (int i = 0; i < n; i++) cout << dist[i] << endl; return 0; }