# include # include #include # include #include #include #include # include # include # include # include # include # include # include # include # include # include # include # include # include # include # include # include # include # include # include # include # include # include #include #include #include using namespace std; using LL = long long; using ULL = unsigned long long; constexpr long long MOD = 1000000000 + 7; constexpr long long INF = std::numeric_limits::max(); const double PI = acos(-1); #define fir first #define sec second #define debug(x) cerr<<#x<<": "< Pll; typedef pair> Ppll; typedef pair>> Pbll; typedef pair>> Pvll; typedef pair Vec2; struct Tll { LL first, second, third; }; typedef pair Ptll; #define rep(i,rept) for(LL i=0;i=0;i--) LL h, w, n, m, k, s, t, q, sum, last, cnt, ans,a[1000],d[100010]; string str; struct Edge { LL to, cost; }; vectorvec[100010]; bool f; char c; void YN(bool f) { if (f) cout << "YES" << endl; else cout << "NO" << endl; } void yn(bool f) { if (f) cout << "Yes" << endl; else cout << "No" << endl; } void dfs(LL u,LL par) { bool F = 0; d[u] = min(d[u], d[par] + 1); rep(i, vec[u].size()) { if (vec[u][i].to != par) { F = 1; dfs(vec[u][i].to, u); d[u] = min(d[u], d[vec[u][i].to] + 1); } } if (!F)d[u] = 0; } int main() { cin >> n; rep(i, n)d[i] = INF / 4; rep(i, n - 1) { LL x, y; cin >> x >> y; x--, y--; vec[x].push_back(Edge{ y,1 }); vec[y].push_back(Edge{ x,1 }); } d[0] = 0; dfs(0, 0); rep(i, n) cout << d[i] << endl; return 0; }