#include <bits/stdc++.h>
using namespace std;

template <typename A, typename B>
string to_string(pair<A, B> p);
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
 
string to_string(const string& s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define fi first
#define se second
#define pb push_back
#define mod(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,a,b) for(int i = a; i < b; i++)
#define forr(i,a,b) for(int i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const int mod = 1e9+7;
int sum(int a, int b){return (a+b) % mod;}
int sub(int a, int b){return (a + mod - b) % mod;}
int mul(int a, int b){return (1ll * a * b) % mod;}
int power(int a,int b){
	int res = 1;
	while(b){
		if(b&1)res = mul(res,a);
		b >>= 1;
		a = mul(a,a);
	}
	return res;
}

const int maxn = 2e5+10;
int N,enCamino[maxn],res[maxn];
vi graph[maxn];

void dfs(int u,int p,int d,int &maxi,int &p1){
	if(d > maxi){
		maxi = d;
		p1 = u;
	}
	for(auto &v : graph[u]){
		if(v == p)continue;
		dfs(v,u,d+1,maxi,p1);
	}
}
int buscaCamino(int u,int p,int fin,vi &path){
	if(u == fin){
		path.pb(u);
		return 1;
	}
	for(auto &v : graph[u]){
		if(v == p)continue;
		if(buscaCamino(v,u,fin,path)){
			path.pb(u);
			return 1;
		}
	}
	return 0;
	
}
void dfs2(int u,int p,int &idx){
	res[u] = idx++;
	for(auto &v : graph[u]){
		if(enCamino[v])continue;
		if(v == p)continue;
		dfs2(v,u,idx);
	}
	idx++;
	
}
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> N;
	forn(i,0,N-1){
		int u,v; cin >> u >> v; u--; v--;
		graph[u].pb(v);
		graph[v].pb(u);
	}
	int p1 = -1,lenDiameter = -1,p2 = -1;
	dfs(0,0,0,lenDiameter,p1);
	lenDiameter = -1;
	dfs(p1,p1,0,lenDiameter,p2);
	debug(p1+1,p2+1);
	vi camino;
	buscaCamino(p1,p1,p2,camino);
	reverse(all(camino));
	
	for(auto &u : camino)enCamino[u] = 1;
	
	int idx = 1;
	for(auto &u : camino){
		res[u] = idx++;
		for(auto &v : graph[u]){
			if(enCamino[v])continue;
			dfs2(v,v,idx);
		}
		
	}
	debug(camino);
	
	forn(i,0,N)cout << res[i] << ' ';
	cout << '\n';
	return 0;
}
/*
__builtin_mul_overflow(x,y,&x)
-fsplit-stack
*/

#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define WT int T=read();while(T--) 
#define NO puts("NO");
#define YES puts("YES");
using namespace std;

inline int read()
{
    char c=getchar();int x=0;bool f=0;
    for(;!isdigit(c);c=getchar())f^=!(c^45);
    for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
    if(f)x=-x;return x;
}

const int M=2e5+10;
int n,a[M],p[M],dis[M][2],f[M],vis[M],s,t,cnt;
int de[M],ff[M][25];
vector<int>e[M];

void dfs1(int u,int fa,int tt)
{
	f[u]=fa;
	for (int i=0;i<e[u].size();i++)
	{
		int to=e[u][i];if (to==fa)continue;
		dis[to][tt]=dis[u][tt]+1,dfs1(to,u,tt);
	}
}

void dfs2(int u,int fa)
{
	p[++cnt]=u;
	for (int i=0;i<e[u].size();i++)
	{
		int to=e[u][i];if (to==fa||vis[to])continue;
		dfs2(to,u);
	}
	for (int i=0;i<e[u].size();i++)
	{
		int to=e[u][i];if (to==fa||(!vis[to]))continue;
		dfs2(to,u);
	}
}


void dp()
{
	for (int j=1;j<=20;j++)
		for (int i=1;i<=n;i++)
			ff[i][j]=ff[ff[i][j-1]][j-1];
}

int LCA(int x,int y)
{
	if (de[x]<de[y])swap(x,y);
	for (int i=20;i>=0;i--)
		if (de[ff[x][i]]>=de[y])x=ff[x][i];
	if (x==y)return x;
	for (int i=20;i>=0;i--)
		if (ff[x][i]!=ff[y][i])
			x=ff[x][i],y=ff[y][i];
	return ff[x][0];
}

int gdis(int u,int v)
{
	return de[u]+de[v]-2*de[LCA(u,v)];
}

void dfs3(int u,int fa)
{
	ff[u][0]=fa;de[u]=de[fa]+1;
	for (int i=0;i<e[u].size();i++)
		if (e[u][i]!=fa)
			dfs3(e[u][i],u);
}

signed main()
{
	n=read();
	for (int i=1;i<n;i++)
	{
		int u=read(),v=read();
		e[u].pb(v),e[v].pb(u);
	}dfs1(1,0,0);
	for (int i=1;i<=n;i++)
		if (dis[i][0]>dis[s][0])s=i;
	dfs1(s,0,1);
	for (int i=1;i<=n;i++)
		if (dis[i][1]>dis[t][1])t=i;
	int l=t;while(l!=s)vis[l]=1,l=f[l];
	dfs2(s,0);dfs3(s,0);dp();a[s]=1;
	for (int i=2;i<=n;i++)
		a[p[i]]=a[p[i-1]]+gdis(p[i],p[i-1]);
	for (int i=1;i<=n;i++)
		cout<<a[i]<<' ';
	return 0;
}
/*

*/