#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define rep(x, to) for (int x = 0; x < (to); x++) #define REP(x, a, to) for (int x = (a); x < (to); x++) #define foreach(itr, x) for (typeof((x).begin()) itr = (x).begin(); itr != (x).end(); itr++) #define EPS (1e-14) using namespace std; typedef long long ll; typedef pair PII; typedef pair PLL; typedef complex Complex; typedef vector< vector > Mat; const int INF = (int)(1e+9 + 7); const int MAX_V = 100005; int N; int L[MAX_V], R[MAX_V]; vector edge[MAX_V]; int dfs(int u, int prev, int depth) { R[u] = depth; rep(i, edge[u].size()) { int v = edge[u][i]; if (v == prev) continue; L[u] = min(L[u], 1 + dfs(v, u, depth + 1)); } if (INF == L[u]) L[u] = 0; return L[u]; } void solve() { rep(i, MAX_V) L[i] = INF; dfs(1, -1, 0); rep(i, N) { cout << min(R[i + 1], L[i + 1]) << endl; } } int main() { cin >> N; rep(i, N) { int x, y; cin>> x >> y; edge[x].push_back(y); edge[y].push_back(x); } solve(); return 0; }