#include<bits/stdc++.h>
using namespace std;
#define MAXN 200005
#define lowbit(x) (x&-x)
#define reg register
#define mp make_pair
#define fir first
#define sec second
typedef long long LL;
typedef unsigned long long uLL;
const int INF=0x3f3f3f3f;
const int mo=1e9+7;
const int iv2=5e8+4;
const int lim=1000000;
const int jzm=1e6+7;
const int orG=3,invG=332748118;
const double Pi=acos(-1.0);
typedef pair<LL,LL> pii;
const double PI=acos(-1.0);
template<typename _T>
_T Fabs(_T x){return x<0?-x:x;}
template<typename _T>
void read(_T &x){
	_T f=1;x=0;char s=getchar();
	while(s>'9'||s<'0'){if(s=='-')f=-1;s=getchar();}
	while('0'<=s&&s<='9'){x=(x<<3)+(x<<1)+(s^48);s=getchar();}
	x*=f;
}
template<typename _T>
void print(_T x){if(x<0){x=(~x)+1;putchar('-');}if(x>9)print(x/10);putchar(x%10+'0');}
int gcd(int x,int y){return !y?x:gcd(y,x%y);}
int add(int x,int y){return x+y<mo?x+y:x+y-mo;}
LL n,ans[2005],tot;pii f[2005];
pii solve1(pii tmp){return mp(tmp.fir+1LL,tmp.sec);}
pii solve2(pii tmp){return mp(tmp.fir,tmp.sec+1LL);}
pii solve3(pii tmp){return mp(tmp.fir+tmp.sec,tmp.sec);}
pii solve4(pii tmp){return mp(tmp.fir,tmp.sec+tmp.fir);}
void extend(LL id){
	tot=id;
	while(f[tot].fir+f[tot].sec<=n){
		if(f[tot].fir<=f[tot].sec)tot++,f[tot]=solve3(f[tot-1]),ans[tot]=3;
		else tot++,f[tot]=solve4(f[tot-1]),ans[tot]=4;
	}
}
LL check(LL id){return n-f[id].fir+id;}
void print(){
	while(f[tot].fir<n)++tot,f[tot]=solve1(f[tot-1]),ans[tot]=1;
	printf("%d\n",tot);for(int i=1;i<=tot;i++)printf("%d\n",ans[i]);
}
signed main(){
	read(n);f[1]=solve2(f[0]);ans[1]=2;f[2]=solve1(f[1]);ans[2]=1;tot=2;extend(tot);
	if(check(tot)<=130){print();return 0;}
	for(int i=3;i<=tot;i++){
		LL las=check(tot);pii ls=f[i];int lasway=ans[i];f[i]=solve1(f[i-1]);ans[i]=1;extend(i);
		if(check(tot)>=las)f[i]=ls,ans[i]=lasway,extend(i);
		//printf("%d:%lld %lld %lld %lld\n",i,f[i].fir,f[i].sec,check(tot),las);
		las=check(tot);ls=f[i];lasway=ans[i];f[i]=solve2(f[i-1]);ans[i]=2;extend(i);
		if(check(tot)>=las)f[i]=ls,ans[i]=lasway,extend(i);
		//printf("%d:%lld %lld %lld %lld\n",i,f[i].fir,f[i].sec,check(tot),las);
		las=check(tot);ls=f[i];lasway=ans[i];f[i]=solve3(f[i-1]);ans[i]=3;extend(i);
		if(check(tot)>=las)f[i]=ls,ans[i]=lasway,extend(i);
		//printf("%d:%lld %lld %lld %lld\n",i,f[i].fir,f[i].sec,check(tot),las);
		las=check(tot);ls=f[i];lasway=ans[i];f[i]=solve4(f[i-1]);ans[i]=4;extend(i);
		if(check(tot)>=las)f[i]=ls,ans[i]=lasway,extend(i);
		//printf("%d:%lld %lld %lld %lld\n",i,f[i].fir,f[i].sec,check(tot),las);
		if(check(tot)<=130){print();return 0;}
		//printf("nxt %lld %lld\n",f[i+1].fir,f[i+1].sec);
	}
	print();
	return 0;
}
/*
0 1
1 1
1 2
*/
#include <bits/stdc++.h>
#define Ri register int
#define ll long long
#define db double
#define FOR(i, j, k) for(Ri i = j; i <= k; i++)
#define DEC(i, j, k) for(Ri i = j; i >= k; i--)
using namespace std;

const int maxn = 2e5 + 100;
int n;
vector<int> g[maxn];
int mx, xm;

int d[maxn];
inline void dfs(int u, int fa) {
	d[u] = d[fa] + 1;
	if(d[u] > mx) mx = d[u], xm = u;
	for(Ri i = 0; i < g[u].size(); i++) {
		if(g[u][i] == fa) continue;
		dfs(g[u][i], u);
	}
}

bool f[maxn];
void tagi(int u) {
	if(!u) return;
	f[u] = 1;
	for(Ri i = 0; i < g[u].size(); i++) {
		if(d[g[u][i]] < d[u]) {
			tagi(g[u][i]);
			break;
		}
	}
}

int out[maxn];
int sol(int u, int fa, int w) {
	out[u] = ++w;
	int h = 0;
	for(Ri i = 0; i < g[u].size(); i++) {
		if(g[u][i] == fa) continue;
		if(f[g[u][i]]) {h = g[u][i]; continue;}
		w = sol(g[u][i], u, w) + 1;
	}
	if(h) w = sol(h, u, w);
	return w;
}

int main() {
	scanf("%d", &n);
	FOR(i, 2, n) {
		int x, y;
		scanf("%d%d", &x, &y);
		g[x].push_back(y);
		g[y].push_back(x);
	}
	mx = 0, xm = 0;
	dfs(1, 0);
	int w = xm;
	mx = 0, xm = 0;
	dfs(w, 0);
	tagi(xm);
	sol(w, 0, 0);
	FOR(i, 1, n) printf("%d ", out[i]);
	return 0;
}

