#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
typedef long long LL;
using namespace std;
int n,ans,powe[100010],head[100010];

struct node{
	int nxt;
	int ed;
	int col;
}edge[200020];

char u;
void scan(int &x){
	int f=1;
    while(u = getchar(), u < '0' || u > '9'){if(u=='-') f=-1;};
    x = u-'0';
    while(u = getchar(), u >= '0' && u <= '9') x = x * 10 + u -'0';
    x*=f;
}

void dfs(int x,int y,int z){
	int j=1;
	for(int i=head[x]; i; i=edge[i].nxt){
		if(edge[i].ed!=y){
			if(j==z) j++;
			edge[i].col=j;
			dfs(edge[i].ed,x,j);
			j++;
		}
	}
}

void work(){
	dfs(1,0,0);
	for(int i=1; i<=(n-1)*2; i+=2){
		printf("%d\n",edge[i].col);
	}
	
}

int main(){
	scan(n);
	int tmp,tmd;
	int j=0;
	for(int i=1; i<=n-1;i++){
		scan(tmp);
		scan(tmd);
		edge[++j].ed=tmd;
		edge[j].nxt=head[tmp];
		head[tmp]=j;
		edge[++j].ed=tmp;
		edge[j].nxt=head[tmd];
		head[tmd]==j;
		powe[tmp]++;
		powe[tmd]++;
	}
	ans=0;
	for(int i=1; i<=n;i++){
		 if(powe[i]>ans) ans=powe[i];
	} 
	printf("%d\n",ans);
	work();
	return 0;
}