#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<utility>
#include<map>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef vector<int> vec;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define stop char nyaa;cin>>nyaa;

vector<int> v[101010];
vector<pair<int, int>> l[101010];
int ans[101010];

int dfs(int x, int p) {
	l[x].push_back({ 0,-1 });
	l[x].push_back({ 0,-1 });
	for (auto to : v[x]) {
		if (to == p)continue;
		l[x].push_back({ dfs(to,x),to });
	}
	sort(l[x].rbegin(), l[x].rend());
	return l[x][0].first + 1;

}

void rdfs(int x, int p) {
	if (p != -1) {
		if (l[p][0].second == x) {
			l[x].push_back({ l[p][1].first + 1,l[p][1].second });
		}
		else l[x].push_back({ l[p][0].first + 1,l[p][0].second });
	}
	sort(l[x].rbegin(), l[x].rend());
	ans[x] = l[x][0].first;

	for (auto to : v[x]) {
		if (to == p)continue;
		rdfs(to, x);
	}
}


void solve() {
	int n;
	cin >> n;
	rep(i, n - 1) {
		int x, y;
		cin >> x >> y;
		--x; --y;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	dfs(0, -1);
	rdfs(0, -1);
	rep(i, n) {
		cout << 2 * (n - 1) - ans[i] << endl;
	}
}


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	//stop
		return 0;
}

