#include using namespace std; int n; vector g[100000]; int dist[100000]; int main() { 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_n(dist, n, 1 << 28); queue q; dist[0] = 0; q.push(0); for (int i = 0; i < n; i++){ if (g[i].size() == 1){ dist[i] = 0; q.push(i); } } while (q.size()){ int p = q.front(); q.pop(); for (int t : g[p]){ if (dist[t] > dist[p] + 1){ dist[t] = dist[p] + 1; q.push(t); } } } for (int i = 0; i < n; i++){ cout << dist[i] << endl; } }