// D - Coloring Edges on Tree
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int N; cin>>N;
	int G[N], C[N-1];
	rp(i, 0, N-1){
		int p; scanf("%d%d", &p, C+i);
		G[--C[i]] = p-1;
	}

	int colors[N], pre_colors[N]; rp(i, 0, N) colors[i] = pre_colors[i] = 0;

	int K = 1;
	rp(c, 1, N){
		int p = G[c];
		int color = pre_colors[p] + 1;
		pre_colors[p] = colors[c] = color==colors[p]? ++color: color;
		K = max(K, color);
	}

	cout<< K <<endl;
	for(int c:C) cout<< colors[c] <<endl;
}