#include #include #include typedef std::int_fast32_t s32; typedef std::uint_fast32_t u32; typedef std::int_fast64_t s64; typedef std::uint_fast64_t u64; const unsigned long mod = 1000000007; const double EPS = 0.00000001; const int INF = (1 << 30); int ans[112345]; std::vector connect[112345]; void dfs(int i, int depth) { if( ans[i] <= depth ) return; ans[i] = depth; for(int j = 0; j < (int)connect[i].size(); ++j) { dfs(connect[i][j], depth + 1); } return; } int main() { int n; std::cin >> n; for(int i = 0; i < n; ++i) { ans[i] = INF; } for(int i = 1; i < n; ++i) { int x, y; std::cin >> x >> y; x -= 1; y -= 1; connect[x].push_back(y); connect[y].push_back(x); } dfs(0, 0); for(int i = 0; i < n; ++i) { if( connect[i].size() == 1 ) { dfs(i, 0); } } for(int i = 0; i < n; ++i) { std::cout << ans[i] << std::endl; } return 0; }