#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; //#define __int64 long long #define long __int64 #define REP(i,a,b) for(int i=a;i to[i+h]){ //ソート基準変更位置 //swap swap(from[i], from[i+h]); swap(to[i], to[i+h]); flg = false; } } if(h <= 1){ if(flg){ break; } }else{ h /= 1.3; } } } int main(){ int n; cin >> n; //初期化 for(int i=1; i<=n; i++){ leaf[i] = true; } kyori[1] = 0; rep(i,n-1){ cin >> from[i] >> to[i]; leaf[from[i]] = false; kyori[to[i]] = kyori[from[i]] + 1; } //一応ソート combsort(n-1); for(int i=n-2; i>=0; i--){ if(leaf[ to[i] ]){ kyori[ to[i] ] = 0; } kyori[ from[i] ] = min(kyori[ from[i] ], kyori[ to[i] ] + 1); } for(int i=1; i<=n; i++){ cout << kyori[i] << endl; } return 0; }