#include using namespace std; int cost[100010]; vector g[100010]; int deg[100010]; int main(){ memset(cost,-1,sizeof(cost)); int n; cin >> n; queue Q; for(int i = 1 ; i < n ; i++){ int a,b; cin >> a >> b; --a,--b; g[a].push_back(b); g[b].push_back(a); deg[a]++; deg[b]++; } for(int i = 0 ; i < n ; i++){ if( i == 0 || deg[i] == 1 ){ Q.push(i); cost[i] = 0; } } while(Q.size()){ int q = Q.front(); Q.pop(); for( auto e : g[q] ){ if( cost[e] == -1 ){ cost[e] = cost[q] + 1; Q.push(e); } } } for(int i = 0 ; i < n ; i++) cout << cost[i] << endl; }