#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> 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; } for(int i=n-1; 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; }